Validation Rules

Validation Rules in Salesforce | A Brief Guide by Salesforce Developer

The main purpose of using Salesforce validation rule verifies that the data a user enters in a record meets the standards you specify before the user can save the record. In case it doesn’t, the validation rule automatically shows an error message with a short explanation of what was entered incorrectly, this restricts user to prevent from saving changes with invalid data. By having such rules, you can avoid incorrect values in the field. 

Usually these Come in the form of required field sets that need to filled out with a particular field change. 

How Do Validation Rules Work?

Validation Rules evaluate or trigger every single time there is an attempt to save the record for a particular field for which the validation rule has been written. 

The formulas contain one or more criteria that should be met in order to pass validation and save the record. 

Simply put, the validation rules check whether a specific field (or multiple fields) corresponds to the mentioned criteria. If the data is evaluated to be true, the record gets saved. If not, the rule displays an error message, specifying the mistakes. This means that unless the user modifies the fields to match the criteria, they won’t be able to go through verification when a new record is created or when changes to an existing one are trying to be saved. 

dont miss out iconDon't forget to check out: Data Quality Control Using Validation Rules | Salesforce Guide

Steps To Create Validation Rules

Step1> Select your Object (Standard/ Custom)

Go to “Setup” section, from the Gear icon then Object Manager from the tab and choose your object from the detailed object list for which you want to create validation rules. 

Steps2> Once you select your object, the object menu preview pane opens up, scroll down to the last and click on Validation Rule. 

Steps 3> Once the Validation Rule page opens up click on New, it will open Object Validation rule page. 

Steps 4> Name the Rule, Tick the “Active” checkbox, and in the “Description” field give a brief explanation of what the rule should do. 

Step5> Creating the Error Condition Formula

Moving on to the “Error Condition Formula Section”, we all need to create a formula that will identify the validation rule criteria. It’ll be made up of the chosen “Function” (on the right, you can see the box, containing a large selection of function categories), the selected field (via the “Insert Field”), and the operator (that’s indicated via the “Insert Operator” button). 

Once you specify your Logic for Validating Field in Error Condition formula Section by using various Functions sections, Insert operator Section (for various Arithmetic tools). Click on check syntax. 

The “Check syntax” Button will help you to evaluate your code logic and specify you “No Error Syntax” or “Error Syntax with Description” by evaluating your Formula. 

dont miss out iconCheck out an amazing Salesforce video tutorial here: Creation Of Validation Rules And Verifying Them In Salesforce

Step6> Defining the Error Message & its Location

The Error Message is a mandatory field when setting up a validation rule. Importantly, this message needs to state what was done wrong, i.e., where the user made a mistake, explaining in short how to make the fix

Step 7> Specify the Error location.

Mention the location of your Error message by choosing the radio button (either on the top of the page or beside the field for which the validation rule is made). 

Finally, click on “Save” button to save the rule. 

Test the rule by creating record and check whether the “Validation Rulework as expected. 


Popular Salesforce Blogs