Validation Rules in salesforce

By | December 13, 2019

Hi, here we are going to learn validation rules in salesforce.

What is Validation Rule?

Validation rules helps to improve data quality by preventing users from saving incorrect data.

Validation rules are executed at record save time.

Validation rules can contain a formula or expression that evaluates the data in one or more fields and returns a value of true or false.

Important functions in validation rules:

These functions we will use in both validation rules and workflows

  • IsNew(): new record and returns true or if the existing record or old record returns false
  • And: if all values are true it returns true, if one or more values are false it returns false
  • OR:  if all expression are false returns false remaining all conditions it returns true
  • IF:  determines if expression are true or false returns a given value if true and another value if false
  • IsPickVal: Determine if the value of picklist field is equal to a text literal we specify

isPickVal validation rule prevent users from creating a account with a record status is “ unvalidated”

  • isChanged: compares the value of a field to the previous value and returns true if the values are different. If the values are same, it returns false
  • priorvalue: returns the previous value of a field

The priorvalue validation rule will fire when the record status changing from “unvalidated” to “validated”

  • isBlank: if expression does not have value it returns true, have value it returns false
  • isNull: if an expression is null(blank) it returns true, it contains value it returns false

Difference between isBlank() and isNull():

Both determines expression has a value it returns true, if does not contains a value it returns false

  • isBlank(): the expression allows both number and text fields
  • isNull(): the expression allows only number fields
  • Today: returns the current date as a date datatype
  • Year: returns the four digit year in number format  of a given date
  • Regex: compares a text field to a regular expression and returns true if there is a match otherwise , it returns false

Navigation for creating Validation rules

Leave a Reply

Your email address will not be published. Required fields are marked *