Validation Rules
Validation Rules in Salesforce are used to ensure the integrity of data and records. They can be written as either expressions or formulas and can be as simple or complex as required but inevitably relies on whether the statement is true or false.
How To Create a Validation Rule
- Go to Setup in the top right corner,
- Go to Object Manager then search for the Object you want the Rule on,
- In the menu on the left, go to Validation Rules,
- Click New
There are 3 components that make up a Validation Rule,
- The name of the Validation Rule,
- The formula, &
- The error message
Common Expressions
PRIORVALUE() – Checks the value of the field prior to it being updated to the new value
ISBLANK() – Checks to see if the field has no value
AND() – Allows you to build up complex logic where multiple statements must be true
OR() – Allows you to build up complex logic where either statement can be true
Examples
Example 1
When changing an Account’s county to Lancashire, the country must be United Kingdom
ISPICKVAL(County=”Lancashire”)
&&
NOT(ISPICKVAL(Country=”United Kingdom”))
Example 2
If an Opportunity is worth more than £1 million, a Project Manager must be assigned.
Amount >= 1000000
&&
ISBLANK(Project_Manager__c)