+ Start a Discussion
anu123anu123 

How to write custom error message in VF page

Hi all,

   i need to write custom error message for unique field not allowing duplicates in vf page. can u give me the sample code.

 

Thanks in advance

anu

Best Answer chosen by Admin (Salesforce Developers) 
r1985r1985

Use the following code in the controller class.

 

 catch(Exception e)
        {
     ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Error'));
          }

 

 

Also add this tag in the vf page.

 

 <apex:pageMessages />

Thanks,

Malar

All Answers

r1985r1985

Use the following code in the controller class.

 

 catch(Exception e)
        {
     ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Error'));
          }

 

 

Also add this tag in the vf page.

 

 <apex:pageMessages />

Thanks,

Malar

This was selected as the best answer
anu123anu123

Thank u for ur reply. thanks a lot