ValidationRule defines an object-scoped business constraint that checks whether record data can be saved. Its formula evaluates one or more fields and returns a Boolean value, meaning true or false. When the rule is active, a true result means the data is invalid and triggers the validation error. It does not mean the record passed validation.
The rule separates enforcement, logic, and feedback: active enables enforcement, errorConditionFormula identifies invalid data, and errorMessage explains the failure. Setting active to false disables the rule without deleting its definition.
Key Elements
| Element | What the Element Controls |
|---|---|
fullName |
The rule's internal name within its parent object's validationRules collection. The rule name starts with a letter, uses letters, numbers, and underscores, cannot end with an underscore, and cannot contain consecutive underscores. The inherited element is required for Metadata API create, update, and delete operations. |
active |
Required. true enables the rule; false leaves the definition present but disables enforcement. |
errorConditionFormula |
Required. The formula that detects invalid data. A true result triggers the error when the rule is active. Field and custom-label dependencies can be embedded in this expression. |
errorDisplayField |
The fully specified field name beside which the error appears. If omitted, or if the field is not visible on the page layout, the error location becomes Top of Page. This element does not determine which fields the formula evaluates. |
errorMessage |
Required. The message shown when validation fails. It must contain no more than 255 characters. |
Behavior and Constraints
A rule's presence in retrieved metadata does not establish that its business constraint is enforced. Check active as well as the formula. An inactive rule retains its formula and message but does not enforce the condition.
Error placement is independent of validation logic. A field can appear only in errorDisplayField, without contributing a value to errorConditionFormula. Conversely, the formula can evaluate fields other than the field selected for displaying the error.
A page layout change can move the error to Top of Page without changing the rule's condition. This happens when the selected errorDisplayField is no longer visible on the layout.
Validation rules do not support compound fields, which combine multiple field parts, such as an address. Validation rules can also be defined for custom metadata types.
Deployment and Retrieval
Rules are represented as validationRules children within CustomObject metadata. In that nested representation, fullName is the rule's internal name, not the object-qualified selection identifier. ValidationRule inherits fullName from the base Metadata type; Metadata API component operations require it when creating, updating, or deleting the rule.
For individual retrieval, use an explicit object-qualified member such as Lead.Rep_Code_Validation, following the pattern ObjectApiName.RuleName. A 2019 retrieval report confirms this form and notes that it is case-sensitive. The portion after the dot is the rule's name, not a field name.
ValidationRule does not support the * wildcard in package.xml. Direct manifest selection therefore requires explicit members.
In source-format deployments, inconsistent file identity can produce a misleading missing-component error. A reported case involved a file whose base name did not match the rule's fullName; matching the two resolved that deployment.
Tooling API payloads use a separate structure. Their Metadata and FullName wrapper fields are distinct from lowercase metadata elements such as description, active, and fullName. A top-level scalar update is not necessarily a valid metadata update.
Relationships
CustomObject contains the rule through validationRules. The rule can reference fields and custom labels, while object translations can identify the rule for translation. Formula dependencies are embedded within an expression rather than stored as one component name. The actual formula determines which dependencies apply; not every rule references a custom field or custom label.
References
-
CustomField:errorConditionFormula,errorDisplayField. A field used for error placement has a different role from a field whose value determines whether validation fails. -
CustomLabel:errorConditionFormula.
Referenced By
-
CustomObjectTranslation:namein validation-rule translation entries. This is an incoming translation relationship, not a reference stored in the rule.
Documentation Inconsistencies
The ValidationRule definition requires errorMessage, but its declarative CustomObject XML example uses validationMessage. That example is inconsistent with the field definition. Use errorMessage for the rule's message element.
Reported Issues
-
A description-only Tooling API update can fail with a misleading formula error. In a 2015 PATCH report, sending top-level
DescriptionproducedREQUIRED_FIELD_MISSINGwith a message referring toValidationFormula. The successful payload placed lowercasedescriptioninsideMetadataand includedactive,errorConditionFormula, anderrorMessage. Tooling API update report. -
Inspecting all formulas may require one definition retrieval per rule. A 2019 report states that Tooling API queries selecting
MetadataorFullNamemust be qualified to return at most one row. The reported approach first lists ruleIdvalues, then retrieves each rule'sMetadataby its record ID and examineserrorConditionFormulafor field references. Per-rule formula retrieval discussion. -
A rule reported as missing from the deployment ZIP may have a file-name mismatch. In a 2025 report, the source file base was
ZSVehicleId_Mandatory, while itsfullNamewasVehicleId_Mandatory. Making the file base andfullNamematch resolved the error that the component named inpackage.xmlwas not found in the ZIP. Source identity mismatch report. -
Warnings about already-absent components can cause a destructive deployment to be reported as failed. A mixed-component deletion report included a missing
ValidationRulewarning. The accepted 2015 answer usedignoreWarnings="true"onsf:deployso missing-component warnings would not fail the deployment. Destructive deployment warning discussion. -
A deactivation PATCH can encounter managed-component restrictions. A 2017 report received
CANNOT_MODIFY_MANAGED_OBJECTwhile attempting to disable a validation rule associated with an object from a managed package. The submittedMetadataincludedactiveset tofalse, the formula, and the error message. The report does not establish that every rule on a packaged object is locked. Managed-component update report.
Common Questions
Does a validation rule fail when its formula returns true?
Yes, if active is true. A true result from errorConditionFormula identifies invalid data and triggers errorMessage.
How do I retrieve one validation rule?
Select ValidationRule with the explicit member ObjectApiName.RuleName, such as Lead.Rep_Code_Validation. Individual retrieval is reported to be case-sensitive. Inside the parent object's metadata, the rule's fullName is just the rule name.
Can I retrieve all validation rules with a wildcard in package.xml?
No. ValidationRule does not support * in package.xml. List explicit members for direct selection.
Why does my validation error appear at the top of the page?
Salesforce uses Top of Page when errorDisplayField is omitted or its field is not visible on the page layout. A layout change can therefore move the error without changing the formula.
How do I disable a validation rule without deleting it?
Set active to false. The rule's definition remains present, including its formula and error message, but the rule no longer enforces the condition.