Sub topic 5
Handling blank values correctly
This chapter assumes you can create a validation rule in Object Manager and read a basic error condition formula. Blank handling is where many rules fail, so it gets its own chapter.
Why blanks cause trouble
A validation rule blocks the save when its formula returns true. If a field is empty, comparisons on it may not behave the way you expect. Take Amount <= 0. In validation formulas, a blank number field is treated as 0 by default, so the comparison is true. That may or may not be what you want.
Use ISBLANK() to test for emptiness explicitly. It returns true when a field has no value. Wrap it in NOT() to require a value to be present before another check runs.
AND(
ISPICKVAL(StageName, "Negotiation/Review"),
OR(ISBLANK(Amount), Amount <= 0)
)This rule blocks the save when the stage is Negotiation/Review and Amount is empty or not positive. Writing both tests makes the intent visible, so a later editor does not have to guess how blanks are treated.
Guard clauses
Some checks only make sense when a value exists. Put NOT(ISBLANK(...)) first so the rule skips empty fields.
AND(
BillingCountry = "USA",
NOT(ISBLANK(BillingPostalCode)),
NOT(REGEX(BillingPostalCode, "\\d{5}(-\\d{4})?"))
)Without the guard, an empty postal code fails the pattern test and the rule blocks every US account that has no postal code. With the guard, the rule checks the format only when someone entered a value. If you also want the field to be required, write that as a separate rule so each error message stays specific.
ISBLANK versus ISNULL
Use ISBLANK() for every field type. ISNULL() is an older function that does not work on text fields in the way ISBLANK() does. Salesforce recommends ISBLANK().
Number, currency, and percent fields have one more gotcha. If the field has a default of 0 or is treated as zero, ISBLANK may return false. Test the actual behavior in your org with a sample record.
Whitespace and text fields
A text field containing only spaces is not always stored as empty. When this matters, compare the trimmed value:
LEN(TRIM(Description)) = 0Use this form when users paste in values that look empty but contain spaces.
Picklists and blanks
Do not call ISBLANK() on a picklist field. Use ISPICKVAL(Field, "") to test for no selection instead. Picklists are covered in the next chapter.
Common mistakes
| Mistake | Effect | Fix |
|---|---|---|
| Testing only `Amount <= 0` | Blank is treated as 0, so intent is unclear | Add `ISBLANK(Amount)` explicitly |
| No guard before `REGEX` | Empty fields fail the pattern | Add `NOT(ISBLANK(field))` |
| Using `ISBLANK` on a picklist | Formula error or wrong result | Use `ISPICKVAL(field, "")` |
| Checking only for an empty string | Whitespace passes | Use `LEN(TRIM(field)) = 0` |
Exercise
Write a validation rule formula that blocks the save when Industry is not blank and Description is blank. Industry is a picklist, so choose the correct function for it.
Show answer
AND(NOT(ISPICKVAL(Industry, "")), ISBLANK(Description)). The picklist is tested with ISPICKVAL against an empty string, and the text field is tested with ISBLANK.