Introduction to Validation Rules
Validation rules verify that data entered by users in records meet the standards you specify before they can save it. A validation rule can contain a formula or expression that evaluates the data in one or more fields and returns a value of “True” or “False.” Validation rules can also include error messages to display to users when they enter invalid values based on specified criteria.
Using these rules effectively contributes to quality data. For example, you can ensure that all phone number fields contain a specified format or that discounts applied to certain products never exceed a defined percentage.
Defining Validation Rules
You can create validation rules for objects, fields, campaign members, or case milestones. In these steps, we’ll create a validation rule that fires when a user tries to save an account with an account number of incorrect length.
Creating a Validation Rule
- From Setup, go to Object Manager and click Account.
- In the left sidebar, click Validation Rules.
- Click New.
- Enter the following properties for your validation rule:
- Rule Name: Account_Number_8_Characters
- Error Condition Formula: LEN( AccountNumber) != 8
- Error Message: Account number must be 8 characters long.
- To check your formula for errors, click Check Syntax.
- Click Save to finish.
Here’s how a validation rule’s error message can appear when a user types an incorrect phone number format into a field.
This training information is very useful to learn about validation in Salesforce.