Validation Rules in Salesforce

Defining Validation Rules in Salesforce

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. 

  1. Goto SetUp>>Customize>>Account(Any Object). 
  2. From the left sidebar click the validation rule. 
  3. Click New. 
  4. Enter the Name of the rule. 
  5. In the Error Condition Formula section define your criteria to validate the data. 
  6. To check the formula or expression for error click on Check Syntax. 
  7. In Error Message section define your message and position which will appear when the user enters the wrong data. 
  8. Finally, Save it. 

dont miss out iconDon'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. 

  1. Goto SetUp>>Customize>>Contact. 
  2. From the left sidebar click the validation rule. 
  3. Click New. 
  4. Enter the Name of the rule i.e. Verify_Age 
  5. In the Error Condition, Formula section define your criteria to validate the data. i.e  Year ( Birthdate) > 1999 
  6. To check the formula or expression for error click on Check Syntax. 
  7. 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 
  8. Finally, Save it. 

Responses

Popular Salesforce Blogs