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

Display Custom Validation Error on Visualforce page
I have a Visualforce page which uses standard controller and controller Extensions, I want to dispaly a Custom Validation Error message on the VF page. Any ideas!
Assuming you are looking to generate an error from your controller, you can use the following.
In the controller:
and in the page:
If that isn't what you are looking for, can you explain a bit more about your scenario?
So do you have a regular validation rule on the quantity field? What behaviour are you looking for? If you are looking for the same behaviour as the standard pages (e.g. an error message displayed beneath the input field) I think you may need to code this yourself. I've found that validation rules in visualforce give a lovely long message referring to the full id of the component that failed the rule.
Hi,
yes you are right !!
i have the standard validation rule for quantity.(i will ignore this)
please help me how can i add error message through controller also !
This won't be a simple fix unfortunately. I think you'll need to create a wrapper class that wraps up an Invoice_Item__c with an error message per field. Then when you are repeating through the list, you will need to check if there is an error associated with the quantity and render the error message out at that point.
ok
Thank you , I will Try that !
so i cannot use the following either ? in controller and VF page ?
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'My error message'));
<apex:pageMessages/>
You can do that, but it will put an error message out wherever pagemessages happens to be - it won't tie in with the element in the list that has failed validation (unless you put out the row number or similar).
Hi Bob,
I have a similar kind of problem.
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. Thanks.