I have a few validation rules which display errors on fields. This is working fine for Standard Pages. But when these validations fail on a VisualForce page, the error messages show on the top of the page in "apex:messages". Is there a way to show these messages on the fields, without re-creating the validation checks in Apex or VisualForce page.

UPDATE: For example:


public PageReference save() {
        update application;
    catch(DmlException e)
        return null;
    catch (Exception e)
        return null;

    return null;


<apex:outputpanel id="Messages">
    <strong><apex:messages style="color:red;"/></strong>
<apex:inputField value="{!application.Field_Having_Validation_Rule__c}" />
  • 1
    Could you show us a bit the current code of your VF page ?
    – brovasi
    Jun 2, 2015 at 6:30
  • I have updated the original post with the code.
    – MAli
    Jun 2, 2015 at 6:37
  • I have solved half of my problem. I missed the part which was causing the error in my original post. This line was causing the error: <apex:commandButton action="{!save}" value="Save" reRender="Messages" status="saveStatus" />. When I removed the reRender attribute, its showing the error on the field. The problem now is that its showing the error on the field as well as top of the page.
    – MAli
    Jun 3, 2015 at 4:34
  • Possibly relevant Ideas Exchange post.
    – Adrian Larson
    Jun 4, 2015 at 23:40

3 Answers 3


You need to reference the id of the inputField element. You will have to create one apex:message for each field I think, not too sure can't remember.

<apex:inputField value="{!application.Field_Having_Validation_Rule__c}" id="Field_Having_Validation_Rule"/> 
<apex:message for="Field_Having_Validation_Rule" styleClass="errorMessage" />

You can find your solution here :

Field level error message

Check this one also VF field level error message

  • Both of these posts require checking for the validation errors in the controller. I do not want to check for these validation errors again as they are defined in validation rules. I need this to work: "salesforce.com/docs/developer/pages/Content/…"
    – MAli
    Jun 2, 2015 at 23:29

After a bit of trial and error of the Salesforce example:

Salesforce Field Validation Example

I figured out the following:

  1. Anything in reRender attribute will cause the validation errors to NOT show.
  2. The duplication of error message is a known issue with Salesforce apex:messages (Known Issue)

For the time being I will consider this as the best solution without any extra coding.

Please let me know if there is any other way of doing it.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .