+ Start a Discussion
Longhorn94Longhorn94 

Displaying VisualForce Error Messages

I would like to create a VisualForce page using a standard controller, that captures and displays the page errors by using <apex:pageMessages />.  Right now, if you call any VisualForce page but encounter an error, for ex calling the page with an invalid identifier, you get a standard Salesforce.com error message:

 

Visualforce Error
Id value 001U0000005W2cu1 is not valid for the Account standard controller

 

I would like for my page to display this error in the styles and configuration I've specified in the page, but instead, my page isn't shown and I get the Salesforce.com error instead.

 

This is possible using a custom controller, where I can trap any errors, add them to the pagemessages collection, then have my VF page check this collection to display the data or the error message using the proper formatting.

 

Appreciate any insight you might have...

 

Longhorn94Longhorn94

Thanks for your reply and the references.  What'd I'd like to do though is to handle any errors from my VF page without using a custom controller (i.e. with the Account standard controller).

 

For example, with a custom controller I can do this:

 

          <apex:pageMessages rendered="{!PageHasError}"/>

          <apex:detail rendered="{!!PageHasError}"/>

 

...where PageHasError is a public property in my custom controller class that indicates whether there was a problem retrieving the account passed to the page from the url.  This will allow my page to display the account details if the account id passed in exists, but will gracefully show the error if it doesn't - i.e. the error is displayed using my VF page formatting and so forth, the rest of my VF page is still rendered.  When using a standard controller, there is no PageHasError property, and instead, VisualForce takes over and renders the error message in the standard Salesforce.com format, and no part of my page is rendered.