Print this page

How to display standard error message in VF Page using standard controller

Knowledge Article Number 000176163
Description On a VF page, is there any way to show the standard error message displayed on the top of the page when it hits validation errors?

Reproducing the issue -
1) Create a VF page that uses a standard controller.
2) Page contains mandatory field so if user doesn't populate mandatory field then error is thrown on field level.
3) But common error message doesn't get displayed on top of page as it displayed on standard pages.
 Even if we use <apex:messages> or <apex:pagemessages> or create an input field and mark it as "required" as follows, it doesn't help:-
<apex:inputField value="{!account.name}" required="true"/>
4) Screenshot of the error message attached.
Resolution Resolution -
None.
There is no way to show the common error message on the top of the page which is shown on standard pages when you hit validation errors.

Workaround -
The common error message can be hard coded in try catch block, written in controller class.
Note: This will however be executed after the client side validation for the required fields has been completed successfully on 'Save'.

Example where this can be used -
You entered a social security in correct format (checked by validation rules) but in your controller class, you found that the social security didn't exist and that's why an exception was displayed on the VF page.

 




Attachments
Name Type Size
TopErrorMsg.jpg
215KB

promote demote