Validation Rules verify that the data a user enters in a record meets your specified standards before saving the record data. A Validation Rule can contain a formula or an expression that evaluates the data in the field and it returns a value in Boolean form i.e. ‘True’ or ‘False’. The validation rule returns ‘True’ which means the data you enter is invalid and ‘False’ confirm data is valid. Validation Rule can also include error messages to display to users for invalid data entry.
Validation Rule Process in Salesforce
Types of Validation Rule in Salesforce are given below and the priority of each rule is according to their order.
- Validation Rules
- Assignment Rules
- Auto-response Rules
- Workflow Rules
- Escalation Rules
If one rule fails then salesforce checks the other validation rule contained in the field or record and displays an appropriate error message at that field or above the Record.
Creating a Validation Rule
Validation rules can create for objects, fields, campaign members, or case milestones.
Steps for creating a validation rule are:
- From Setup, go to Object Manager.
- Select the object or field.
- In the left sidebar, click Validation Rule.
- Enter the condition.
- Then click Save to finish.
Validation Rule Used For
The main purpose of a validation rule is to make sure that the data that the user has input, updated, or removed on a record is valid or not for the specified standards that the user wants and it checks before saving it. If it doesn’t, the validation rule automatically shows an error message, preventing the user from saving the changes with invalid data. By having such rules, you can avoid incorrect data and might save a lot of time and effort.
How Do Validation Rule Work
Validation rules trigger every single time when we save the record. Validation rules check whether a specific field (or fields), object corresponds to the indicated criteria. If the data is correct, then the record gets saved. If not, the rule displays an error message, with the error. Unless the user modifies the fields to match the standards, they won’t be able to proceed via verification when a new record is created or when changes on an existing one are trying to be saved.
The important point to remember for the Validation Rule
- Check all the settings in your organization that can make a record fail validation.
- Not to create a contradicting validation rule for a field.
- When using a validation rule for a field, make sure those objects are deployed.
- Using checkbox fields simplify your validation formulas, that do not require any operator because they return true or false.
Example of Validation Rule in Salesforce
- The most common Salesforce validation rule example is restricting users from entering data in the wrong format. For example, the date was entered in MM-DD-YY format instead of DD-MM-YY.
- Mainly used for restricting the field changes. For example, by setting up a validation rule, you can limit the field and not allow it to be changed back.
- Validation rules show an error or restrict saving the record by verifying the condition.
- Another example scenario could be using the validation feature when there exists a connection with dependencies between several fields.
- Verifying ranges of numbers is also a use case.