Set AccountID and ContactID on autoconvert lead class (Salesforce)

609 Views Asked by At

I am calling on the Apex Class below in a Salesforce flow and want to autoconvert the lead into an existing account and contact but I am stuck with setting the AccountID and ContactID from values from my flow

Public class AutoConvertLeads 
{     @InvocableMethod   
    public static void LeadAssign(List<Id> LeadIds) 
    public Flow.interview.Flow_template_gallery myFlow {get; set;}
    {         
        LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];    
        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();    
        for(id currentlead: LeadIds){                
            Database.LeadConvert Leadconvert = new Database.LeadConvert();    
            Leadconvert.setLeadId(currentlead);                               
            Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);             
            Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion  
            Leadconvert.setAccountId(MyFlow.getVariableValue('varAccountID'));
            Leadconvert.setContactId(currentlead);
            MassLeadconvert.add(Leadconvert);    
        }                  
        if (!MassLeadconvert.isEmpty())
        {            
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);       
        }    
    } 
}

I added in two methods 'setAccountID' and 'setContactID' which should be variables I have from my salesforce flow

1

There are 1 best solutions below

0
On

You can paas arguments in class, through flow.