3

I am trying to write a trigger or wf for a field to be updated if a Multi-select picklist has more than one value. Any suggestions on how to write if the multi-select has more than one value

  • 4
    In Apex you can split the field on ';' (the separator used in multi-select picklist selections) and check the size of the result. – Keith C Oct 7 '15 at 14:05
  • Depending on the length of the Multi-select, you could also assess the content of the field for actual values. However, that would also require modifications to the trigger every time a new value is added to the the list. – HomerJ Oct 7 '15 at 14:10
1

As Keith C and HomerJ said you can write something like this. Hope this helps.

trigger UpdateOpportunity on Opportunity (before insert, before update){    
    for(Opportunity opp :Trigger.new){ 

        // MultiSelect Fields are a single String with values delimited by a semi-colon
        // DeliveryInstallationStatus__c is a Picklist (Multi-Select)
        String[] deliveryArray = opp.DeliveryInstallationStatus__c.split(';');
        if(deliveryArray.size()>0){
            // Write your logic here
        }
    }   
}
0

Multiselect Picklist values are de-limited by a semi-colon ";" .To get expected result, add the field values to a string/list and split the string/list to get the count of multiselect picklist values. Below example shows a Opportunity Trigger to get the count of multiselect picklist values.

    if(Trigger.isupdate || Trigger.isinsert){

         for(Opportunity opp : Trigger.new){

            system.debug('----MultiSelect Picklist Values----'+ opp.OpportunityProductLog__c);
            List<String> lstOpportunityMultiselectPicklist = opp.OpportunityProductLog__c.split(';');
            system.debug('----List Size ----'+ lstOpportunityMultiselectPicklist .size());
            if(!lstOpportunityMultiselectPicklist.isEmpty() && lstOpportunityMultiselectPicklist.size() > 1)
            {
                //Code
            }
         }
    }

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.