function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Salesforce SamuraiSalesforce Samurai 

How do I create a Case formula with Contains (text)?

 

So, I'm struggling with the syntax of a formula to create some buckets or groups.

When the value of a text field contains, X, Y, Z, etc., return X, Y, Z, etc. 

Field - Plan Group:

Formula(theoretical):

Case( Plan_Name__c,
Contains(Plan_Name__c, "X"), "X",
Contains(Plan_Name__c, "Y"), "Y",
...

Does anyone know a clean way to write this into a formula? I have about 6-7 groups that I am trying to create.

Best Answer chosen by Admin (Salesforce Developers) 
Steve :-/Steve :-/

you can't use CASE and CONTAINS like that, you need to use IF and CONTAINS like this:

IF(CONTAINS(Text_1__c, "A"), "Group A",
IF(CONTAINS(Text_1__c, "B"), "Group B",
IF(CONTAINS(Text_1__c, "C"), "Group C", NULL)))

 

All Answers

Steve :-/Steve :-/

you can't use CASE and CONTAINS like that, you need to use IF and CONTAINS like this:

IF(CONTAINS(Text_1__c, "A"), "Group A",
IF(CONTAINS(Text_1__c, "B"), "Group B",
IF(CONTAINS(Text_1__c, "C"), "Group C", NULL)))

 

This was selected as the best answer
Steve :-/Steve :-/

are you all set with this or do you still need help?

Salesforce SamuraiSalesforce Samurai

This answers my question, thank you for the quick response.

 

 

Renan QueirozRenan Queiroz
Is it possible with LEFT/MID and FIND:
CASE(
    LEFT(Your_String__c, FIND("FIND-TEXT", Your_String__c)),
    "String1", "Result1",
    "String2", "Result2",
    "String3", "Result3",
    "Default Result"
)
;)