0

I am trying to set up an if statement inside a formula field for a multi select picklist.

Essentially I want to know if the user has selected one particular value on it's own. For example: If the picklist has values of "a", "b", "c", ... "z".

I want to set an if statement of the type If (val == "c") then do something. It shouldn't include any other values.

3
  • @Eric was absolutely correct. If you have a few values, you can check all of them to see if it just has a single value, but that is impractical if you're over about 50 or so because of formula limits. All conventional means we'd use, like TEXT(Field__c) do not work on a multiselect list, so this is one of those few cases where we'd have to resort to code. – sfdcfox Feb 1 '17 at 23:39
  • @Eric post your response again please so I can accept it as the correct answer. Thank you. – Arthlete Feb 1 '17 at 23:42
  • @Arthlete - Done – Eric Feb 2 '17 at 1:48
2

You would have to check to see if it included each value like this which could be a problem depending on how many values you have. Also you would need to remember to update it each time you added pickable values:

IF(INCLUDES( myList__c , "A"), 2, 0) + IF(INCLUDES( myList__c , "B"), 2, 0) + 
IF(INCLUDES( myList__c , "C"), 1, 0) + IF(INCLUDES( myList__c , "D"), 2, 0) + 
IF(INCLUDES( myList__c , "E"), 2, 0) + IF(INCLUDES( myList__c , "F"), 2, 0)

and check that the value = 1

otherwise you would have to do this via trigger since the only functions available for MS Picklists are Includes or ispickval (i forget which) which does not indicate if other values are there or not.

Pretty simple before update and insert trigger

Assume Picklist API name is myList__c Assume indicator field is onlyHasC__c

trigger check values on xyz(before insert, before update){

for(sObject o : trigger.new){
    if(o.myList__c == 'c')
            o.onlyHasC__c = true;
    else
            o.onlyHasC__c = false

}

}
6
  • You could easily do that using a formula, can't you? Otherwise in trigger just split it to a set<String> and check if the set contains the value 'c' – Salesforcesmarty Feb 1 '17 at 23:20
  • 1
    o.MyList__c == 'c' is all that you need. Really no need to do all that splitting and such. – sfdcfox Feb 1 '17 at 23:23
  • @sfdcfox - go catch. thinking to hard – Eric Feb 1 '17 at 23:24
  • @Salesforcesmarty - the catch is checking to ensure it ONLY has that value. the formula at the end of my answer is a way to do it – Eric Feb 1 '17 at 23:27
  • @sfdcfox is there an easier way to do it with a formula then instead of involving a trigger? – Arthlete Feb 1 '17 at 23:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.