Skip to main content
replaced http://salesforce.stackexchange.com/ with https://salesforce.stackexchange.com/
Source Link

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 LinkReferred 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?

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?

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?

deleted 29 characters in body; edited tags; edited title
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

How to findFind the countCount of selected Multi-picklist in Salesforce ApexSelect Picklist?

I was searching for a Methodmethod to find the count of selected Multimulti-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 Multimulti-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 ListList and Splitthe 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. IsAre there any direct methods to check the count instead of ListList and Split method using ';'. As I can see thissplit ? This approach was suggested somewhere 2013 and just want to know any new methods availbeavailable recently.

  2. DoseDoes the above code have any loop holesloopholes? As I couldn't find any issue till now.

How to find the count of selected Multi-picklist in Salesforce Apex?

I was searching for a Method to find the count of selected Multi 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 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 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. Is there any direct methods to check the count instead of List and Split method using ';'. As I can see this was suggested somewhere 2013 and just want to know any new methods availbe recently

  2. Dose the above code have any loop holes? As I couldn't find any issue till now.

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?

Tweeted twitter.com/StackSalesforce/status/825896960641089536
Source Link
Robert Thomas
  • 1.8k
  • 4
  • 34
  • 57

How to find the count of selected Multi-picklist in Salesforce Apex?

I was searching for a Method to find the count of selected Multi 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 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 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. Is there any direct methods to check the count instead of List and Split method using ';'. As I can see this was suggested somewhere 2013 and just want to know any new methods availbe recently

  2. Dose the above code have any loop holes? As I couldn't find any issue till now.