Newer Version Available
ValidationRule
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.
As of API version 40.0, you can use validation rules with custom metadata types.
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 formula defined in
the validation rule. If the formula returns a value of true, an error message is displayed.
See “Define Validation Rules” in the Salesforce online help. |
| errorDisplayField | string | The fully specified name of a field in the application. If a value is supplied, the error message appears next to the specified field. If you do not specify a value or the field isn’t visible on the page layout, the value changes automatically to Top of 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 object. White spaces and special
characters are escaped for validity. The name must:
Inherited from the Metadata component, this field isn’t 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>Wildcard Support in the Manifest File
This metadata type doesn’t support the wildcard character * (asterisk) in the package.xml manifest file. For information about using the manifest file, see Deploying and Retrieving Metadata with the Zip File.