function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Validation Error Message on VF page



I have a VF page, on this page I need to display the standard validation error message on Save.

The validation rule has been written on the custom object.

But, when I try to save the VF page, the message doesn't appaer in propoer format.

I get the error message llike this:


System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, End Date can't be less than Start Date.: 

Error is in expression '{!save}' in component <apex:page> in page new_process
Can somebody pls, tell me how can I get the message displayed properly on the VF page.
Sumit KumarSumit Kumar



Under save action in controller catch the error message and display in to the visualforce page


below is the sample code -


Catch(Exception Ex){
              if(Ex.getMessage().Contains('Validation error message')){
                    ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,System.Label.Custom LabelName);



In visualforce page write


<apex:PageMessages id="Error"/>



<script type="text/javascript" src=""></script>
Sumit KumarSumit Kumar

<apex:pageMessages/> tag to your page


try {inert} catch(DMLException e) {}  in yours controller

<script type="text/javascript" src=""></script>

<script type="text/javascript" src=""></script>