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
devloper sfdcdevloper sfdc 

how to count items and how to get item of Multi selected picklist using trigger

Hello friend 

I need to count Multi select picklist selected items and how to read those item using trigger.
for count i have create formula filed that working fine, but i dont want to use formula filed.
my objective if we selected two item in a list  then  two case created with  subject name  and subject name is  item value .


trigger onandoffboardingticket on Case (before insert) {

             List<SelectOption> objNames = new List<SelectOption>();
            List<Case>newCace=new List<Case>();
            List<String> recordType=new List<String>{'zCampusHelp_Internal'};
                
             
            
               for(case c :trigger.new)
               {
                       
                       for(Integer i=1;i<=c.Count__c;i++)
                       {
                       
                           Case cas=new case();
                           cas.AccountId=c.AccountId;
                           cas.Subject=c.Subject;
                           cas.Onboarding_Offboarding_Employee__c=c.Onboarding_Offboarding_Employee__c;
                           cas.Status=c.Status; 
                        
                           cas.ContactId=c.ContactId;
                           cas.Internal_Category__c=c.Internal_Category__c;
                           cas.Internal_Type__c=c.Internal_Type__c;
                           cas.Internal_Item__c=c.Internal_Item__c;
                           newcace.add(cas);
                       }
                       }
               
    insert newcace;
}
Best Answer chosen by devloper sfdc
AmitdAmitd
Hi,

You can simply retrive the multiselect picklist in a string and then split that string by ";". This should help you

for(Case c : trigger.new){
  string pl = c.yourpicklistfield;
 if(!string.isBlank(pl)){
         list<string> pls =  pl.split(';');
         for(string str : pls){
               your new case record
          }
 }

}

All Answers

AmitdAmitd
Hi,

You can simply retrive the multiselect picklist in a string and then split that string by ";". This should help you

for(Case c : trigger.new){
  string pl = c.yourpicklistfield;
 if(!string.isBlank(pl)){
         list<string> pls =  pl.split(';');
         for(string str : pls){
               your new case record
          }
 }

}
This was selected as the best answer
devloper sfdcdevloper sfdc
but how to cout how many items are selected in 
 picklist 
devloper sfdcdevloper sfdc
Thanks Amit it is work.