back to resources
CASE FUNCTION IN FORMULA FIELDS
August 11 2022 • 10 min read

BUSINESS CHALLENGE

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.

case 4

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.

CASE FUNCTION

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.

  1. Click on Object Manager and Select Account Object.

  2. Click Fields and Relationship → Click New.

case 1

  1. Select Formula Data Type → Click Next.

case 2

  1. Enter Field Name as “Billing State Region” → Select Return Type as Text.

case 3

  1. 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) 

case 4

  1. Click Next.

  2. 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.

case 5

9.  Add the field to the required page layouts and click Save.

TESTING THE FORMULA FIELD

  1. Create or Update an Account record. Enter the Country information and save the record 

  2. Notice the formula field we created, it will update Billing State Region based on the value of the Billing Country automatically.

    case 6

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

Your email address will not be published

© 2022 Digital Biz Tech