---
schema_version: "1"
id: 58bb8fc8b4e0677decec5909ae47bf8bed7e7f007932e8d293bf6760ba910f68
title: ValidationRule
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/api_meta/meta_validationformulas.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_validationformulas.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 7775d71b51566c30447ad4573a500051d1da6eea90efbd078683eadd94847052
description: 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.
---
# 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](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/metadata.htm "The base class for all metadata types. You can’t edit this object. A component is an instance of a metadata type.") 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

<table class="featureTable sort_table" summary="">



          <thead class="thead sorted" align="left">
            <tr>
              <th class="featureTableHeader  " id="d948333e98">Field Name</th>

              <th class="featureTableHeader  " id="d948333e101">Field Type</th>

              <th class="featureTableHeader  " id="d948333e104">Description</th>

            </tr>

          </thead>

          <tbody class="tbody">
            <tr>
              <td class="entry" headers="d948333e98" data-title="Field Name"><span class="keyword parmname">active</span></td>

              <td class="entry" headers="d948333e101" data-title="Field Type">boolean</td>

              <td class="entry" headers="d948333e104" data-title="Description">Required. Indicates whether this validation rule is active,
                (<samp class="codeph nolang">true</samp>), or not active
                (<samp class="codeph nolang">false</samp>).</td>

            </tr>

            <tr>
              <td class="entry" headers="d948333e98" data-title="Field Name"><span class="keyword parmname">description</span></td>

              <td class="entry" headers="d948333e101" data-title="Field Type">string</td>

              <td class="entry" headers="d948333e104" data-title="Description">A description of the validation rule.</td>

            </tr>

            <tr>
              <td class="entry" headers="d948333e98" data-title="Field Name"><span class="keyword parmname">errorConditionFormula</span></td>

              <td class="entry" headers="d948333e101" data-title="Field Type">string</td>

              <td class="entry" headers="d948333e104" data-title="Description">Required. The formula defined in the validation rule. If the
                formula returns a value of <samp class="codeph nolang">true</samp>, an error message is displayed. </td>

            </tr>

            <tr>
              <td class="entry" headers="d948333e98" data-title="Field Name"><span class="keyword parmname">errorDisplayField</span></td>

              <td class="entry" headers="d948333e101" data-title="Field Type">string</td>

              <td class="entry" headers="d948333e104" data-title="Description">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 <samp class="codeph nolang">Top of Page</samp>.</td>

            </tr>

            <tr>
              <td class="entry" headers="d948333e98" data-title="Field Name"><span class="keyword parmname">errorMessage</span></td>

              <td class="entry" headers="d948333e101" data-title="Field Type">string</td>

              <td class="entry" headers="d948333e104" data-title="Description">Required. The message that appears if the validation rule fails.
                The message must be 255 characters or less.</td>

            </tr>

            <tr>
              <td class="entry" headers="d948333e98" data-title="Field Name"><span class="keyword parmname">fullName</span></td>

              <td class="entry" headers="d948333e101" data-title="Field Type">string</td>

              <td class="entry" headers="d948333e104" data-title="Description"> The internal name of the object. White spaces and special
                characters are escaped for validity. The name must:<ul class="ul bulletList">
                  <li class="li">Contain characters, letters, or the underscore (_)
                    character</li>

                  <li class="li">Must start with a letter</li>

                  <li class="li">Can’t end with an underscore</li>

                  <li class="li">Can't contain two consecutive underscore characters.</li>

                </ul>
                <p class="p">Inherited from the <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/metadata.htm" title="The base class for all metadata types. You can’t edit this object. A component is an instance of a metadata type.">Metadata</a> component, this field isn’t defined in
                  the WSDL for this component. It must be specified when creating,
                  updating, or deleting. See <a class="xref" href="https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_create.htm" title="Deprecated. Adds one or more new metadata components to your organization asynchronously. This call is removed as of API version 31.0 and is available in earlier versions only. Use createMetadata() instead.">create()</a> to see an example of this field
                  specified for a call.</p>
              </td>

            </tr>

          </tbody>

        </table>

## Declarative Metadata Sample Definition

A sample XML definition of a validation rule in a custom object is shown in this code block.

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
    <deploymentStatus\>Deployed</deploymentStatus\>
    <fields\>
        <fullName\>Mommy\_Cat\_\_c</fullName\>
        <label\>Mommy Cat</label\>
        <referenceTo\>Cat\_\_c</referenceTo\>
        <relationshipName\>Cats</relationshipName\>
        <type\>Lookup</type\>
    </fields\>
    <label\>Cat</label\>
    <nameField\>
        <label\>Cat Name</label\>
        <type\>Text</type\>
    </nameField\>
    <pluralLabel\>Cats</pluralLabel\>
    <sharingModel\>ReadWrite</sharingModel\>
    <validationRules\>
        <fullName\>CatsRule</fullName\>
        <active\>true</active\>
        <errorConditionFormula\>OR(Name = &apos;Milo&apos;,Name = &apos;Moop&apos;)</errorConditionFormula\>
        <validationMessage\>Name must be that of one of my cats</validationMessage\>
    </validationRules\>
</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](https://developer.salesforce.com/docs/atlas.en-us.264.0.api_meta.meta/api_meta/file_based_zip_file.htm).

- [← Previous](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_apexsharingrecalculation.htm "SharingRecalculation")
- [Next →](https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_weblink.htm "WebLink")