Skip to main content
2 of 3
deleted 29 characters in body; edited tags; edited title
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

How to Find the Count of Multi-Select Picklist?

I was searching for a method to find the count of selected multi-select picklist. My aim is to select multiple options for Known-Languages in a Drop down and to display the selected count in a Counter and reflect the changes of count based on selection from multi-select picklist using Insert-Update before trigger.

But couldn't able to find a direct one and was able to see some workaround way using a List and the split method using ';' and it worked well (Referred Link)

I have written my trigger as below and it worked fine with my test cases.

trigger AccountMultiselect on Account (before insert, before update) {
    for(Account acc:Trigger.new){
        if(String.isNotBlank(acc.Languages_Known__c)){
            List<String> Langs = acc.Languages_Known__c.split(';');
            acc.Counter__c     = Langs.size();
        } else {
            acc.Counter__c     = 0;
        } 
     
    }
}

Can some one let me know

  1. Are there any direct methods to check the count instead of List and split ? This approach was suggested somewhere 2013 and just want to know any new methods available recently.

  2. Does the above code have any loopholes?

Robert Thomas
  • 1.8k
  • 4
  • 34
  • 57