When it comes to picklist in formula fields, there are few things which developer need to consider.
- Do you want picklist actual value (return text value)?
- Do you want to check if user has selected a specific value (return true or false.)?
There are 3 functions that can be used for different purpose to work with picklists in formula field.
ISPICKVAL(<Picklist_Field>, ‘Text Value To Compare’)
Return Type: Boolean
This function returns TRUE if the picklist value matches the text value mentioned. Else returns false. This can be combined with other functions like, IF, AND, OR etc.
CASE(<Picklist_Field>, ‘Case_1’, ‘Value_1’, ‘Case_2’, ‘Value_2’, ‘Case_3’, ‘Value_3’, ‘Case_4’, ‘Value_4’, ‘Default_Value’)
Return value as per the match with CASE key selected in Picklist field.
This function can return any value, like text or Boolean or number. It all depends on what value you want to return based on the picklist value. You can also use IF, AND, OR and other conditions to fetch specific value as per requirement.
CASE(Stagename, ‘Closed-Won’,’Green’, ‘Closed-Won’,’Red’, ‘In Progress’,’Blue’ , ‘Qualification’,’Orange’, ‘Needs Analysis’,’Orange’, ‘White’)
Return type: String
This function will return the text value that is selected in the picklist field. Usually this is used as a combination with other conditions in formula field.