You need to sign in to do that
Don't have an account?

How To Get Validation Errors On VFPages
Hi,
Any body help me!...
HOw to get Validation errors on VFPage?
Thank U
You need to sign in to do that
Don't have an account?
Hi,
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: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();
}
}
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.
Please let me know if you have any idea about how to display an custom validation error message.