Available in: both Salesforce Classic and Lightning Experience
Available in: Contact Manager, Group, Professional, Enterprise, Performance, Unlimited, Developer, and Database.com Editions
Consider all the settings in your organization that can make a record fail validation, including assignment rules, field updates, field-level security, or fields hidden on a page layout.
Be careful not to create contradicting validation rules for the same field; otherwise, users won’t be able to save the record.
A poorly designed validation rule can prevent users from saving valid data. Make sure you thoroughly test a validation rule before activating it. You can also use the debug log to monitor the details of your rule implementation.
When referencing related fields in a validation formula, make sure those objects are deployed.
Use the RecordType.Id merge field in your formula to apply different validations for different record types.
You don’t have to begin a validation rule formula with the IF function. Any Boolean error condition expression works. For example:
Correct: CloseDate < TODAY()
Incorrect: IF(CloseDate < TODAY(), TRUE, FALSE)
Keep in mind that when a validation rule contains the BEGINS or CONTAINS function, it processes blank fields as valid. For example, if you have a validation rule that tests whether the serial number of an asset begins with “3”, all assets with a blank serial number are considered valid.
When using a validation rule to ensure that a number field contains a specific value, use the ISBLANK function to include fields that don’t contain any value. For example, to validate that a custom field contains a value of ‘1’, use the following validation rule to display an error if the field is blank or any other number:
OR (ISBLANK (field__c), field__c<>1)
Avoid using the IsClosed or IsWon opportunity merge fields in validation formulas. Instead, use the ISPICKVAL function to determine if the Stage contains the appropriate value. For example, the following validation formula makes a custom Project Start Date field required whenever the Stage is “Closed Won”:
Simplify your validation formulas by using checkbox fields, which don't require any operator because they return true or false. For example, the following validation formula checks to be sure an opportunity has opportunity products using the HasOpportunityLineItem merge field before users can save a change to it:
Tips for Writing Validation Rule Error Messages
Give instructions. An error message like “invalid entry” doesn’t tell the user what type of entry is valid. Write something more specific, such as “Close Date must be after today.”
Always include the field label. Users might not know what field is failing validation, especially if the error message appears at the top of the page.
When defining validation rules, you can set the error location to Top of Page or Field. If the error location is set to a field that is later deleted, to a field that is read only, or to a field that isn’t visible on the page layout, Salesforce automatically changes the location to Top of Page.
If you have a multilingual organization, translate your error messages. You can translate error messages using the Translation Workbench.
Assign corresponding numbers to validation rules and their error messages. This allows you to identify the source of the error.