SFDC configuration

Case In Formulae Fields Salesforce

In this blog we will talk about a very powerful function used in formulae field i.e. case function
Case function is used to create a clean and simplified version of formulae which can replace clumsy nested if formulas.

lets take an example to understand this. Lets assume you get a requirement that based on opportunity stage you need to show tentative number of days opportunity can stay in that stage.
To accomplish this, traditionally admins use if condition and check if stage name is ‘abc‘ then return 2 else if stage name is ‘def‘ then return 3 and so on..
If you have lot of values in stage picklist field then the formulae field becomes very clumsy and it becomes difficult to understand.

To avoid this, you can use case function. The syntax for case function is as below :-
CASE(Expression, result 1, return 1, result 2, return 2, result 3, return 3, ……. , catch all)


First parameter is the expression you want to evaluate. In our case we want to check the stage name
Second parameter will be what is the result you expect from the expression.
Third parameter will be the value you want to return when second expression evaluates to true in comparison of first parameter.

There is a a last parameter as well named catch-all. This is value you want to return when non of the values evaluates to true.

Let take consideration of same above example and see how easy and readable this function can be while managin the requirement.
You can have formulae like below

CASE(TEXT(StageName), ‘Open’, 2, ‘Prospect’, 3, ‘Closed lost’, 4, ‘Closed won’ , 5 , 6)

In above formulae we are checking if stage name equals various stages and accordingly we are returning the value

This expression is more easy to maintain and develop in comparison to nested if conditions.

Leave a Reply