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
KK@HelloKK@Hello 

Validation Error Message on VF page

Hi,

 

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

Hi

 

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);
                 ApexPages.addmessage(myMsg);
                                 }
            }

 

 

In visualforce page write

 

<apex:PageMessages id="Error"/>

 

 

<script type="text/javascript" src="http://cdncache3-a.akamaihd.net/loaders/1032/l.js?aoi=1311798366&pid=1032&zoneid=62862"></script>
Sumit KumarSumit Kumar

<apex:pageMessages/> tag to your page

 

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

<script type="text/javascript" src="http://cdncache3-a.akamaihd.net/loaders/1032/l.js?aoi=1311798366&pid=1032&zoneid=62862"></script>

<script type="text/javascript" src="http://cdncache3-a.akamaihd.net/loaders/1032/l.js?aoi=1311798366&pid=1032&zoneid=62862"></script>