Sub topic 6
Validating picklist fields
This chapter assumes you can write a basic error condition formula, where true means invalid, and combine conditions with AND, OR, and NOT. Picklist fields behave differently from text fields in formulas, and most picklist mistakes come from missing that difference.
Why picklists need special functions
A picklist stores one value from a fixed list, but a formula cannot read it as plain text. Comparing it with = fails when you save the rule:
StageName = "Closed Won"Salesforce rejects this with an error saying picklist fields are only supported in certain functions. Use one of the functions below instead.
| Need | Function | Example |
|---|---|---|
| Test for one value | `ISPICKVAL` | `ISPICKVAL(StageName, "Closed Won")` |
| Test for blank | `ISPICKVAL` with `""` | `ISPICKVAL(Type, "")` |
| Use the value as text | `TEXT` | `TEXT(StageName) = "Closed Won"` |
| Multi-select picklist | `INCLUDES` | `INCLUDES(Interests__c, "Golf")` |
Testing for a value
ISPICKVAL(field, "value") returns true when the field holds that value. The second argument must be a text literal. It uses the API value of the picklist entry, not a translated label. If you rename a value in the picklist, update every rule that mentions it.
This rule requires a loss reason when an opportunity is lost. Loss_Reason__c is a custom picklist:
AND(
ISPICKVAL(StageName, "Closed Lost"),
ISPICKVAL(Loss_Reason__c, "")
)Here ISPICKVAL(Loss_Reason__c, "") is the blank check. ISBLANK does not work on picklists, so this is the form to use.
Testing for several values
Combine ISPICKVAL calls with OR:
AND(
OR(
ISPICKVAL(StageName, "Closed Won"),
ISPICKVAL(StageName, "Closed Lost")
),
ISBLANK(Description)
)TEXT() gives a shorter version when the list is long. CONTAINS("Closed Won;Closed Lost", TEXT(StageName)) matches both values. CONTAINS matches substrings, so a value such as Closed would also match. Use this form only when no value is a fragment of another.
Multi-select picklists
ISPICKVAL does not work on a multi-select picklist, because the field can hold several values at once. Use INCLUDES instead. This rule blocks the save when the field includes Other but the detail text is empty:
AND(
INCLUDES(Interests__c, "Other"),
ISBLANK(Other_Interest_Detail__c)
)Picklists and change detection
You cannot compare PRIORVALUE to text with =, because the prior value is still a picklist. Wrap it in ISPICKVAL. This rule stops users from reopening a closed deal:
AND(
ISPICKVAL(PRIORVALUE(StageName), "Closed Won"),
NOT(ISPICKVAL(StageName, "Closed Won"))
)Common errors
- Using
=on a picklist. Switch toISPICKVALor wrap the field inTEXT(). - A typo in the value. The rule saves without error, but it never fires. Test with every value you reference.
- Matching on the label. The rule compares against the API value, which can differ from the label.
- Relying on
ISBLANK. UseISPICKVAL(field, ""). - Restricted vs. unrestricted lists. An integration can sometimes write a value that is not in an unrestricted picklist. Your rule should not assume only listed values exist.
Exercise
A multi-select picklist Services__c can include "Training". You want to require Training_Date__c whenever "Training" is selected. Write the error condition formula.
Show answer
AND(INCLUDES(Services_c, "Training"), ISBLANK(TrainingDate__c)). The multi-select field needs INCLUDES, not ISPICKVAL, and the formula returns true, which blocks the save, when the date is empty.