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
ShivaShiva 

How to use validation rule?

I have created VF page by extending the standard object. And I have created a validation rule for a field in the object. But it is not working may be because of custom page. Please can someone tell me how to invoke the rule in custom page?

 

Thanks in advance.

Edwin VijayEdwin Vijay
When you use an inputfield tag the validation rule will be applied by default i believe...
Message Edited by Edwin1 on 06-30-2009 08:06 PM
psl_vilaspsl_vilas

Use following tag in your custom visual force page......

 

<font color="red"><apex:messages styleClass="error" /> </font>

 

It will show your validation rule error message.

sfdcfoxsfdcfox

A few more tips:

 

1) Make sure you use <apex:inputField value="{!object.field}" /> notation. This "binds" the value to the object's field, which will in turn force field validation such as requiredness and custom validations.

 

2) Make sure the field appears on the page, or strange things can happen (usually, validation won't run at all for the field, but more often an unresolvable error will pop up).

 

3) Make sure you are calling "{!save}", "{!update}", etc in order to invoke a DML that will validate the page; re-rendering the page also usually works to trigger validations (this is sometimes unfortunate, actually).

 

A "messages" block is not necessary except for page-level exceptions (validation rules that target "top of page" instead of a field). Your error should be displayed on the field(s) which fail validation.