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;
}
}
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
Post a Comment