You need to sign in to do that
Don't have an account?

how to show validation error mesage in custom vf page
Hi every one,
I have created a custom vf page with custom controller. i want to show the validation error message at the particular fields, same as standard error messages. Below is my custom controller.
public with sharing class checkController {
public Contact con{get;set;}
public Account org {get;set;}
public Integer i {get;set;}
public checkController(){
con = new Contact();
intake = new Intake_Coun__c();
org = new Account();
}
private string fromCharArray(list<string> l)
{
string res='';
for(string s : l)
{
res+=s+';';
}
return res;
}
public pagereference SubmitOrg()
{
try{
Account acc = checkAccountExist(org.Name);
if(acc != null)
{
populateAccount(acc);
acc.Submitted_Online__c=true;
acc.Date_Submitted__c = Date.today();
update acc;
}
else
{
org.RecordTypeId ='XXXXXXXXX';
insert org;
acc = org;
}
con.Primary_Contact__c = true;
con.RecordTypeId='XXXXXXXXXX';
con.AccountId=acc.Id;
con.npe01__Preferred_Email__c = 'work';
con = upsertContact(acc.id);
return initRoot();
}
catch(exception ex)
{
return null;
}
}
public pagereference SubmitI()
{
try{
Contact c = upsertContact(null);
if(intake.Contact__c == null)
intake.Contact__c = c.id;
intake.Submitted_Online__c = true;
intake.Date_Submitted__c = Date.today();
insert intake;
return initRoot();
}
catch(Exception dmle)
{
ApexPages.addMessages(dmle);
return null;
}
}
private void populateContact(Contact c, Contact c2)
{
c.FirstName = c2.FirstName ;
c.LastName = c2.LastName ;
c.Phone = c2.Phone ;
c.Email = c2.Email ;
c.leadsource = c2.leadsource ;
c.RecordTypeId = c2.RecordTypeId;
}
private void populateAccount(Account acc)
{
acc.Name=org.Name;
acc.Phone=org.Phone;
acc.Fax=org.Fax;
}
private Contact upsertContact(string accIdToNew)
{
Contact c = checkContactExist(con.email);
if (c != null){
populateContact(c,con);
update c;
}
else{
con.AccountId = accIdToNew;
insert con;
c= con;
}
return c;
}
public Pagereference initRoot()
{
Pagereference page = Page.Root;
page.setredirect(true);
return page;
}
}
Can any one help ome over here.
Regards,
kiran.
I have created a custom vf page with custom controller. i want to show the validation error message at the particular fields, same as standard error messages. Below is my custom controller.
public with sharing class checkController {
public Contact con{get;set;}
public Account org {get;set;}
public Integer i {get;set;}
public checkController(){
con = new Contact();
intake = new Intake_Coun__c();
org = new Account();
}
private string fromCharArray(list<string> l)
{
string res='';
for(string s : l)
{
res+=s+';';
}
return res;
}
public pagereference SubmitOrg()
{
try{
Account acc = checkAccountExist(org.Name);
if(acc != null)
{
populateAccount(acc);
acc.Submitted_Online__c=true;
acc.Date_Submitted__c = Date.today();
update acc;
}
else
{
org.RecordTypeId ='XXXXXXXXX';
insert org;
acc = org;
}
con.Primary_Contact__c = true;
con.RecordTypeId='XXXXXXXXXX';
con.AccountId=acc.Id;
con.npe01__Preferred_Email__c = 'work';
con = upsertContact(acc.id);
return initRoot();
}
catch(exception ex)
{
return null;
}
}
public pagereference SubmitI()
{
try{
Contact c = upsertContact(null);
if(intake.Contact__c == null)
intake.Contact__c = c.id;
intake.Submitted_Online__c = true;
intake.Date_Submitted__c = Date.today();
insert intake;
return initRoot();
}
catch(Exception dmle)
{
ApexPages.addMessages(dmle);
return null;
}
}
private void populateContact(Contact c, Contact c2)
{
c.FirstName = c2.FirstName ;
c.LastName = c2.LastName ;
c.Phone = c2.Phone ;
c.Email = c2.Email ;
c.leadsource = c2.leadsource ;
c.RecordTypeId = c2.RecordTypeId;
}
private void populateAccount(Account acc)
{
acc.Name=org.Name;
acc.Phone=org.Phone;
acc.Fax=org.Fax;
}
private Contact upsertContact(string accIdToNew)
{
Contact c = checkContactExist(con.email);
if (c != null){
populateContact(c,con);
update c;
}
else{
con.AccountId = accIdToNew;
insert con;
c= con;
}
return c;
}
public Pagereference initRoot()
{
Pagereference page = Page.Root;
page.setredirect(true);
return page;
}
}
Can any one help ome over here.
Regards,
kiran.
1) http://www.infallibletechie.com/2012/10/how-to-display-error-messages-in.html
2) http://bobbuzzard.blogspot.com/2011/04/field-level-error-messages-with.html
3) http://www.oyecode.com/2013/10/error-message-handling-and-custom-check.html
Visualforce page:
<apex:pageMessages />
Apex Controller:
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error Message.');
ApexPages.addMessage(myMsg);
(Or)
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Error Message.'));