Yet another blog

Tag Archives: Valida

Capture only the Validation Rule Error message to display in VF page


I had a scenario where i have a VF page which saves records into a custom object. And i was having the controller code in a try catch block to capture the exceptions and was using the getmessage to display the error messages.

But this all the time spit out a lot of ugly stuff along with the error message

” Upsert Failed : First exception on row 0: first error;


All i wanted to show was that Quantity cannot be empty. thats exactly what the end user only wanted to know and all that crap of Upsert failed doesnt make any sense at all.

I had thought of capturing the error message in a string and split it with FIELD_CUSTOM_VALIDATION_EXCEPTION. then displaying the second item in the list to show the error message.

All this seem to be too complicated for this. Indeed there is something very simple to do this.

All you got to do is to add

<apex:pageMessages />

in your VF page. this will capture all your validation errors and diplay it.