In Salesforce sometimes we have to populate a field's value based on the value of some other field. In such cases we can use the IF function in a formula field.
But you may have to use many IF functions if the controlling field has a wide range of input values. To overcome this we can use the CASE function instead.
Here we are going to use the CASE function to create a formula field which displays a different value based on a picklist field value.
WHAT IS A FORMULA FIELD
Formula Field is a read-only field that derives its value from a formula expression you define. The formula field is updated when any of the source fields change.
The CASE() function is a powerful Salesforce tool that allows users to simplify formula writing, stay within compile limits, and create cleaner, easier to read functions versus using long and clunky nested IF() statements.
CREATE A FORMULA FIELD
1.Click the gear icon at the top of the home page and click on setup.
Click on Object Manager and Select Account Object.
Click Fields and Relationship → Click New.
- Select Formula Data Type → Click Next.
- Enter Field Name as “Billing State Region” → Select Return Type as Text.
- This formula displays North America as the formula field’s value if the value of the BillingCountry field is USA, India if the BillingCountry value is Asia and Null if the BillingCountry value is not among any of the mentioned values in the CASE function. Enter the below mentioned formula and click on check the syntax to ensure that you have entered the correct syntax.
CASE( BillingCountry , "USA", "North America", "India", "Asia", "Colombia", "South America", "Australia", "Oceania" Null)
Under Establish Field Level Security, grant edit and read access to required profiles using the Visible and Read-Only checkboxes respectively. Formula fields are always read only, so read only checkbox is checked on by default. Click Next.
9. Add the field to the required page layouts and click Save.
TESTING THE FORMULA FIELD
Create or Update an Account record. Enter the Country information and save the record
Notice the formula field we created, it will update Billing State Region based on the value of the Billing Country automatically.
WRAPPING IT UP
In this blog we have covered how to use the CASE function in a Formula Field to display a specific value depending on the value of another field.
Leave a Comment