0

I'm having problem showing errors in my page, I have validation rule on the custom_object__c which I have created and its Active but when I try to save the page instead of getting the validation rule error on my apex:pageMessages I'm getting Visualforce Error

here is the erorr showing:

System.DmlException: Update failed. First exception on row 0 with id XXXXX; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION ]

Error is in expression '{!Save}' in component in page employeePage: Class.EmployeeCtrl.Save:

What do I need to do to show error on apex:pageMessages?

  • try to use try catch block and check the exception message. ? I guess you will get the above update filed error but also you will get the message.. totally you will get 2 error message. – Ratan Paul Jun 23 '16 at 13:27
3

You should try like this :

try {  
    insert Account;
} 
catch (DMLException e) {
    ApexPages.addMessages(e);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.