Validation rules and Formulas in Salesforce
Validation rules and Formulas in Salesforce:
1. Validation rules can be attached to fields. They are executed when a record
is created or updated.
2. When defining a validation rule, an error condition and error message are
defined. If evaluation of error condition results in true value, record is not
saved, and the error message is generated.
3. Some fields are of type Formula. They are derived from other fields.
Validation rules and formula follow the same expression language.
4. A set of functions used in Formulae are included below.
TODAY() Returns todays date
IF(expr,x,y) if expr is evaluated to true, x is returned, else y is returned
TEXT(field) Returns the text value of a picklist
ISPICKVAL(field,value) Checks whether value of field matches the input parameter. Returns true if there is a match
ISBLANK(field) Returns true if field is blank
AND(expr1,expr2) Performs a logicla AND
OR(expr1,expr2) Performs a logicla OR
HYPERLINK(url,text) Creates a link to the specified url
ISCHANGED(field) Checks id the field’s value has changed
PRIORVALUE(field) Returns the previous value of field
ISNEW() Returns true if a new record is being created.
INUMBER() Returns true if the field is a number
IMAGE() Used to display an image
REGEX() Compares a text field to a regular expression and returns true if there is a match
VLOOKUP() In an object consisting of key value pair, VLOOKUP returns value for a key
5. Methods are used in Formulae fields, Validation rules, Workflow rules,
Field updates, Default values and Approval process. Some of these
methods are only available in certain areas. CASE, IF, ISNUMBER are
available in all places. IMAGE is available only in formulae fields. VLOOKUP
is available only in validation rules.
6. Cross-object formulae span two or more objects by referencing merge