Validation Rule
With this post, we will learn about Validation Rule, which are criteria defined to validate the data entered by the user when creating or manipulating the records. This event occurs after the save button has been clicked. This can contain the formula or expression that validates the data and returns ‘true’ or ‘false’. It can also return an error message associated with that particular validation rule so that the user can see it when he enters invalid data. A validation rule can be created for an object, a field, a campaign member, or a case milestone.
Steps:
Follow the step to create a validation rule for the object.
- Goto SetUp>>Customize>>Account(Any Object).
- From the left sidebar click the validation rule.
- Click New.
- Enter the Name of the rule.
- In the Error Condition Formula section define your criteria to validate the data.
- To check the formula or expression for error click on Check Syntax.
- In Error Message section define your message and position which will appear when the user enters the wrong data.
- Finally, Save it.
Don’t forget to check out: Create Sharing Rules Unit in Salesforce – Learn Here
Example:
Now we are going to write a validation rule for contact objects which fires when contact is saved. This rule validates whether a contact’s age is more than 18 years or not. This will cause an error when contact’s age is less than 18.
- Goto SetUp>>Customize>>Contact.
- From the left sidebar click the validation rule.
- Click New.
- Enter the Name of the rule i.e. Verify_Age
- In the Error Condition, Formula section define your criteria to validate the data. i.e Year ( Birthdate) > 1999
- To check the formula or expression for error click on Check Syntax.
- In the Error Message section define your message and position which will appear when the user enters the wrong data. i.e. Contact must be more than or equal to 18 years
- Finally, Save it.