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
vinothkumar palanivelvinothkumar palanivel 

how to get multi picklist value in apex trigger

Gulafsha MohammedGulafsha Mohammed
Hello Vinothkumar,
Please refer : https://success.salesforce.com/answers?id=9063A000000e1PvQAI
Please mark this as best answer so that others will also benefit.
Thanks,
Gulafsha
Khan AnasKhan Anas (Salesforce Developers) 
Hi Vinoth,

Greetings to you!

Below is the sample code. Kindly modify the code as per your requirement .
 
trigger MultiPicklist1 on Account (before insert, before update) {

    for(Account acc :Trigger.new){ 
        // MultiSelect Fields are a single String with values delimited by a semi-colon
        // Multi_Pick__c  is a Picklist (Multi-Select)
        String[] deliveryArray = acc.Multi_Pick__c .split(';');
        if(deliveryArray.size()>0){
            // Write your logic here
            System.debug('deliveryArray-> ' + deliveryArray);
        }
    }   
}


I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Khan Anas
Raj VakatiRaj Vakati

This in multipicklist like strings splitted by  ";". 
 
trigger MultiPicklist1 on Account (before insert, before update) {

    for(Account acc :Trigger.new){ 
        // MultiSelect Fields are a single String with values delimited by a semi-colon
        // Multi_Pick__c  is a Picklist (Multi-Select)
        List<String>  deliveryArray = acc.Multi_Pick__c .split(';');
        if(deliveryArray.size()>0){
            // Write your logic here
            System.debug('deliveryArray-> ' + deliveryArray);
        }
    }   
}

 
Ajay K DubediAjay K Dubedi
Hi Vinothkumar,

Below Sample Code can fulfill your requirements. Hope this will work for you.

Trigger :

trigger CheckDescription_Trigger on Lead (before update) {      
    if(trigger.Isbefore && trigger.Isupdate)
    {
        List<Lead> leadNewList = new List<Lead>();
        For(Lead LeadObj : Trigger.New){
            If(LeadObj.LeadSource == 'Upwork'){
                leadNewList.add(LeadObj);
                
            }
            
            if(leadNewList.size() > 0)
            {
                CheckDescription_Class.checkDescription(leadNewList);
            }
            
        }   
    }
}


Class :

public class CheckDescription_Class { 
    public static void checkDescription(List<Lead> leadList)
    { 
        if(leadList.size() > 0)
        {
            List<String> pickListValuesList= new List<String>();
            List<String> finalpickListValuesList= new List<String>();
            schema.DescribeFieldResult fd = Cloudanalogy_User__c.Project_Skills__c.getdescribe();
            list<schema.PicklistEntry> pc = fd.getpicklistvalues();
            for( Schema.PicklistEntry pickListVal : pc)
            {
                pickListValuesList.add(pickListVal.getvalue());
            }   
            
            String skillSetString = '';
            for(Lead LeadObj : leadList)
            {
                for(String listobj : pickListValuesList)
                {  
                    if(LeadObj.Description.contains(listobj) )
                    {
                        finalpickListValuesList.add(listobj);
                        skillSetString = skillSetString + ',' +'\''+ listobj + '\'';
                    }
                }
            }
            system.debug('finalpickListValuesList>>>>>>'+finalpickListValuesList);
            skillSetString = skillSetString.removeStart(',');
            system.debug('skillSetString>>>>>>>'+skillSetString);
            
            List<Cloudanalogy_User__c> cloudanalogy_UserList = new List<Cloudanalogy_User__c>();
            if(skillSetString != '')
            {
                //cloudanalogy_UserList = [SELECT Id, Name,Lead_Count__c,Project_Skills__c,Device_Id__c,Username__c FROM Cloudanalogy_User__c WHERE Project_Skills__c INCLUDES (:'skillSetString')];
                cloudanalogy_UserList = database.query('SELECT Id, Name,Lead_Count__c,Project_Skills__c,Device_Id__c,Username__c FROM Cloudanalogy_User__c WHERE Project_Skills__c INCLUDES ('+skillSetString+')');
            }
            
            system.debug('cloudanalogy_UserList>>>>>>'+cloudanalogy_UserList);
        }
    }
}

Please mark this as best answer if this solves your problem.

Thank you,
Ajay Dubedi