function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

To Display Error Messages..

Hai All,

      I have small Doubt,

How to display Error message Under a Custom field(not SObject field) or item in Visualforce through Apex.


<apex:page controller="exampletest">

<apex:form >

   <apex:pageBlock >

          <apex:pageBlockButtons >

                <apex:commandButton value="Save" action="{!save}" />


        <apex:pageBlockSection >

            <apex:pageBlockSectionItem >

                <apex:outputLabel value="Required Field" />

                <apex:outputPanel styleClass="requiredInput" layout="block" >

                    <apex:outputPanel styleClass="requiredBlock" layout="block"/>

                    <apex:inputText value="{!requiredFieldName}" />



            <apex:pageMessages />






public class exampletest {

public String requiredFieldName {get;set;}

  public void save(){

        if ( requiredFieldName == null || requiredFieldName == '' ){

            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter a value in the Required Field'));





Hai premnath,

Thanks for ur reply.I need to display under the field itself.I had 20 number of custom fields.

As according to you that error message will display where evere we put PageMessage in the page.


Your question is not yet clear.


Error messages means how can you get ,,, What is the pur pous of that messages 

you mean required or something else




You can't place Error message under every field by using normal tags of SF in VFP's


However if you need to achieve this you need to use HTML script at each field to disply that error message.

which need a bit custom coding in HTML.


<apex:inputfield ......>
<div class="errormessage" style="display:none;" id="errmsg"><strong>Error:</strong> Error Message</div>


Currenty i don't have any sample script to give to you.