Sub topic 1
What Validation Rules Do and When They Fire
Prerequisites
Assume you know Salesforce objects, fields, records, and the basics of Setup and Object Manager. You should also be comfortable reading simple formulas.
What Validation Rules Do and When They Fire
A validation rule checks a record when Salesforce saves it. The rule blocks the save when its formula evaluates to TRUE. Salesforce then displays an error message, and the user must correct the data before saving again.
Validation rules run for record creation and updates. They can affect saves from the Salesforce interface, imports, integrations, and automation that performs a save. They do not continuously monitor records after they are saved.
Anatomy of a Validation Rule
A validation rule has four important parts:
| Part | Purpose |
|---|---|
| Error condition formula | Returns `TRUE` when the record is invalid |
| Error message | Explains what the user must fix |
| Error location | Shows the message beside a field or at the top of the page |
| Active status | Determines whether Salesforce evaluates the rule |
For example, a rule can require an Opportunity to have a positive Amount when its stage is Negotiation/Review.
Writing the Error Condition Formula
Write the formula from the invalid condition, not the valid condition. This formula returns TRUE only when the record should be rejected:
AND(
ISPICKVAL(StageName, "Negotiation/Review"),
OR(ISBLANK(Amount), Amount <= 0)
)The formula says, “The stage is Negotiation/Review, and Amount is blank or not positive.” A useful error message is: Enter a positive Amount before moving this Opportunity to Negotiation/Review.
Combining Conditions with Logical Operators and Functions
Use these functions to express business logic:
AND(condition1, condition2)requires every condition to be true.OR(condition1, condition2)requires at least one condition to be true.NOT(condition)reverses a result.ISBLANK(field)checks whether a field has no value.ISPICKVAL(field, "Value")compares a picklist value.
Parentheses make the intended grouping clear. Test formulas with blank values and each relevant picklist value before activating them.
Exercise
When does the Opportunity formula above block a save?
Show answer
It blocks the save only when StageName is Negotiation/Review and Amount is either blank or less than or equal to zero.