PradysTechBlog

Yet another blog

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

Hi,

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;

FIELD_CUSTOM_VALIDATION_EXCEPTION Quantity cannot be empty

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.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: