No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
ValidationRule
Represents a validation rule, which is used to verify that the data a user enters in a record is valid and can be saved. A validation rule contains a formula or expression that evaluates the data in one or more fields and returns a value of true or false. Validation rules also include an error message that your client application can display to the user when the rule returns a value of true due to invalid data. This type extends the Metadata metadata type and inherits its fullName field.
As of API version 20.0, validation rules can't have compound fields. Examples of compound fields include addresses, first and last names, dependent picklists, and dependent lookups.
Version
Validation rules are available in API version 12.0 and later.
Fields
| Field Name | Field Type | Description |
|---|---|---|
| active | boolean | Required. Indicates whether this validation rule is active, (true), or not active (false). |
| description | string | A description of the validation rule. |
| errorConditionFormula | string | Required. The validation formula, as documented in the validation formula page. See “Defining Validation Rules” in the Salesforce online help. |
| errorDisplayField | string | The fully specified name of a field in the application. If a value is supplied in this field, the value in errorMessage appears next to the specified field. If you do not specify a value, the error message appears at the top of the page. |
| errorMessage | string | Required. The message that appears if the validation rule fails. The message must be 255 characters or less. |
| fullName | string | The internal name of the validation rule, with white spaces and special characters escaped for validity. The name can only contain characters, letters, and the underscore (_) character, must start with a letter, and cannot end with an underscore or contain two consecutive underscore characters. Inherited from the Metadata component, this field is not defined in the WSDL for this component. It must be specified when creating, updating, or deleting. See create() to see an example of this field specified for a call. |
Declarative Metadata Sample Definition
A sample XML definition of a validation rule in a custom object is shown below.
1<?xml version="1.0" encoding="UTF-8"?>
2<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
3 <deploymentStatus>Deployed</deploymentStatus>
4 <fields>
5 <fullName>Mommy_Cat__c</fullName>
6 <label>Mommy Cat</label>
7 <referenceTo>Cat__c</referenceTo>
8 <relationshipName>Cats</relationshipName>
9 <type>Lookup</type>
10 </fields>
11 <label>Cat</label>
12 <nameField>
13 <label>Cat Name</label>
14 <type>Text</type>
15 </nameField>
16 <pluralLabel>Cats</pluralLabel>
17 <sharingModel>ReadWrite</sharingModel>
18 <validationRules>
19 <fullName>CatsRule</fullName>
20 <active>true</active>
21 <errorConditionFormula>OR(Name = 'Milo',Name = 'Moop')</errorConditionFormula>
22 <validationMessage>Name must be that of one of my cats</validationMessage>
23 </validationRules>
24</CustomObject>