+ Start a Discussion
Sameer VitsSameer Vits 

How to pass picklist value as function parameter in a trigger

Public class AutoConvertLeads
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
            Database.LeadConvert Leadconvert = new Database.LeadConvert();
            Leadconvert.setLeadId(LeadIds[0]);
            lead l= [SELECT Id, email FROM Lead WHERE id=:LeadIds[0]];
            LeadStatus Leads= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
            contact[] clist=[select id,name,session__c from contact where email=:l.email limit 1 ];
            
            if(clist.size()>0){
                contact c=clist[0];
                c.session__c='PUT_THE_VALUE_YOU_WANT_TO_UPDATE_THE_FIELD_WITH'; //Make sure you are inserting value according to field type.
                update c;
            }
            else{    
                Leadconvert.setConvertedStatus(Leads.MasterLabel);
                Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion 
                Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
                System.assert(Leadconverts.isSuccess());
           }
   }
}
The session value comes from web to lead form depending on person signing up. It's a picklist. The values are dates as mentioned - May 24; 2 PM - 4 PM, June 28; 9 AM - 12 PM, May 24; 10 AM -12 PM, June 28; 4:30 PM - 7:30 PM, July 26; 9 AM - 12 PM, July 26; 4:30 PM - 7:30 PM. 

How can I pass these values into this trigger code for c.session__c ?
 
Pradeep SinghPradeep Singh
Hi Sameer, Have you tried Lead Conversion Field Mapping for the same ? Is there any specific reason to go for trigger..?
Narender Singh(Nads)Narender Singh(Nads)
Hi Sameer,
Is there any custom field on lead object which is storing the picklist values?
Sameer VitsSameer Vits
@Pradeep Singh - The lead conversion process is using auto-convert to convert from lead to contact. We are trying to allow customers to do the form as many times as they want but after they do the form we are converting them to contacts. In conversion process, we don't want to create duplicate contacts but only update the field for those who already exists in the system. 
Sameer VitsSameer Vits
@Narender Singh - Yes, the custom field is under Leads labeled as Session. The field type is picklist and all these values are in it. 
Narender Singh(Nads)Narender Singh(Nads)
In that case you should pass the list of lead records instead of IDs of those records. Because in an invocable method you can at most pass just one parameter.