+ Start a Discussion

How To Get Validation Errors On VFPages



Any body help me!...


HOw to get Validation errors on VFPage?


Thank U






There are two ways to get validation errors on the visual force page:

         1. Using javascript syntax to get validation error for vf component.

         2. Using apex:pagemessages class to get any errors at page.


            VF Code:

                                                <apex:page controller="NewAndExistingController" tabstyle="Account">


                                                                <apex:pageBlock mode="edit">



                                                                                                <apex:inputField value="{!Account.name}"/>

                                                                                                <apex:inputField value="{!Account.phone}"/>

                                                                                                <apex:inputField value="{!Account.industry}"/>


                                                                                <apex:pageBlockButtons location="bottom">

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






            Controller code:

                                                public class NewAndExistingController


                                                                public Account account {get; private set;}

                                                                public NewAndExistingController() {

                                                                Id id = ApexPages.currentPage().getParameters().get('id');

                                                                account = (id == null) ? new Account() :

                                                                [SELECT name, phone, industry FROM account WHERE id = :id];


                                                                public PageReference save()


                                                                                try {


                                                                                } catch(System.DMLException e) {


                                                                                return null;


                                                                                // After Save, navigate to the default view page:

                                                                                return (new ApexPages.StandardController(account)).view();



Nisar AhmedNisar Ahmed

Hi Pradeep,


I need to display an custom validation error message for an 'inputText' field in the page itself i.e., by using Javascript.

For Example:

Here, I need to display an error message if the inputText for 'Name' is null or empty.


<div style="position:absolute; top: 145px; left: 30px;" class="cnt_popup">
<div style="position:absolute; top: 140px; left: 105px; height:20px; width:200px;" >
     <apex:inputText id="name" value="{!Name}" styleClass="textarea" required="true">                                    

 Please let me know if you have any idea about how to display an custom validation error message.