How to Add Custom Error Message on Catch

Code:

try
{
          // Code Logic
}

catch(Exception e){
if(e.getMessage().contains('FIELD_CUSTOM_VALIDATION_EXCEPTION, Enter valid Date'))
{
Apexpages.addMessage(new ApexPages.Message (ApexPages.Severity.ERROR, 'Please Enter valid Date'));
return Null; 

else if(e.getMessage().contains('FIELD_CUSTOM_VALIDATION_EXCEPTION,  Too Large Data'))
{
Apexpages.addMessage(new ApexPages.Message (ApexPages.Severity.ERROR, 'Please fill 20 character data in field')); 
}
else
{      
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,e.getmessage()));        
return Null;
}
 } 

Comments

Popular posts from this blog

Salesforce Spring 16 Release Exam (Maintenance Exam Q&A) for Developer 201 Admin

Show Hyper Link On Add Error in Salesforce Trigger

Show the Success Message before Redirecting the Detail page on Visualforce Page