Sub topic 2
Handling Blank Values Correctly
Assume you know Salesforce objects, fields, records, and basic formula syntax. A validation rule runs when a record is saved. Its formula describes an invalid state. When the formula returns TRUE, Salesforce blocks the save.
Handling blank values correctly
Use ISBLANK(field) when a value is optional in some situations but required in others. Combine it with the condition that makes the value required:
AND(
ISPICKVAL(StageName, "Negotiation/Review"),
OR(ISBLANK(Amount), Amount <= 0)
)This rule blocks an Opportunity when its stage is Negotiation/Review and its Amount is blank or not positive. The OR matters because a blank Amount should be handled separately from a numeric comparison.
A common mistake is checking only whether a field is blank. That may reject records in stages where the field is not yet needed. Put the business condition first, then test the field value.
Validating picklist fields
Use ISPICKVAL to compare a picklist. Do not compare a picklist directly with =.
ISPICKVAL(StageName, "Negotiation/Review")TEXT(StageName) can convert a picklist to text when you need to use it in a larger text expression, but ISPICKVAL is clearer for a direct comparison.
Error messages and where they appear
Write an action-oriented message, such as:
Enter a positive Amount before moving the Opportunity to Negotiation/Review.
Choose Field location when one field needs correction. Choose Top of Page when the rule depends on several fields or when no single field explains the problem.
Validating only on create or on change
Use ISNEW() for new records and ISCHANGED(field) for edits. PRIORVALUE(field) returns the field's previous value.
AND(
NOT(ISNEW()),
ISCHANGED(Amount),
NOT($Permission.Can_Edit_Opportunity_Amount)
)This blocks Amount changes on existing records unless the user has the custom permission.
Exercise
Which function should you use to prevent a rule from blocking an unchanged existing record?
Show answer
Use ISCHANGED(field) for the field that must not change, usually together with NOT(ISNEW()) when the rule applies only to edits.