Validation rules verifies the data entered by a user meets a specific standard before he saves the record. To verify, it uses a formula or expression that evaluates the data in one or more fields and returns a value of “True” or “False.” A returned value of “True”, implies that the data entered by the user contains an invalid value. When creating a validation rule, we can include error messages to display to users when they enter values which are invalid for the set criteria. Validation rules helps to keep the data clean and standardized.
For instance, Validation rules can be used to ensure that all phone number fields contain a specified format.
Requirement
We can create validation rules for objects, fields, campaign members, or case milestones. Here we will create a validation rule that fires when a user tries to save a Contact. The validation rule will prevent any user who tries to save the Contact whose mailing postal code not matching with the shipping postal code of the Account associated with it.
Steps
Create a validation rule that displays an error message and prevents a user from creating or updating a contact if both conditions are true.
- Rule Name: Contact_must_be_in_Account_ZIP_Code
- Operator: AND (return true if both conditions are true)
- Define two error conditions:
- The contact is associated with an account id (Using the ISBLANK and NOT functions).
- The contact mailing zip code is different than the account shipping zip code(Using the <> (Not Equal) operator).
Enter an error message for the validation rule.
Creating a Validation Rule
- From Setup, go to Object Manager and click Contact.
- In the left sidebar, click Validation Rules.
- Click New.

- Enter the following properties for the validation rule as shown in the screenshot:
a. Rule Name
b. Error Condition Formula

- Type in the Error Message to be displayed when the validation rule returns ‘True’.
- Click Check Syntax to check your formula for errors.
- Click Save to finish.

- Now we may try to save a Contact under an Account.
- When we type in a Mailing Zip/Postal code different from the Shipping postal code of the parent Account, we will hit an error message.

To learn more about validation rules, click Validation Rules (salesforce.com)
Take Five Consulting is a technology company, based in Virginia U.S., that specializes in the Mortgage Banking vertical especially LOS implementation and application development. Take Five Consulting creates and implement mortgage technology and software specifically for Mortgage Industry.