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
UrsfriendlyUrsfriendly 

How To Get Validation Errors On VFPages

Hi,

 

Any body help me!...

 

HOw to get Validation errors on VFPage?

 

Thank U

 

 

 

 

Pradeep_NavatarPradeep_Navatar

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:form>

                                                                <apex:pageBlock mode="edit">

                                                                   <apex:pageMessages/>

                                                                                <apex:pageBlockSection>

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

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

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

                                                                                </apex:pageBlockSection>

                                                                                <apex:pageBlockButtons location="bottom">

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

                                                                                </apex:pageBlockButtons>

                                                                </apex:pageBlock>

                                                </apex:form>

                                                </apex:page>

 

            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 {

                                                                                upsert(account);

                                                                                } catch(System.DMLException e) {

                                                                                ApexPages.addMessages(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">
Name: 
</div>
<div style="position:absolute; top: 140px; left: 105px; height:20px; width:200px;" >
     <apex:inputText id="name" value="{!Name}" styleClass="textarea" required="true">                                    
     </apex:inputText>  
</div>

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