• Valentin ROLLAND 16
  • NEWBIE
  • 0 Points
  • Member since 2023

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello,

I'm utilizing the Database.LeadConvert class invoked from a flow to auto convert lead records.  I also want to set the AccountId and ContactId (shows in bold/italic below as the variables ExistingAccountID and ExistingContactId) from fields I am populating on the Lead record.  I'm not quite sure how to select and declare them in the class.  I am only converting one record at a time and I will be passing the ID variable (LeadIds) from a Flow to the Apex class, not sure if that makes a difference as this looks like a mass convert for multiple Lead records.  This is the method I'm using from Automation Champion:

Public class AutoConvertLeads
{ @InvocableMethod
public static void LeadAssign(List<Id> LeadIds)
{
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.setAccountId(ExistingAccountId);
Leadconvert.setContactId(ExistingContactId);

Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion
MassLeadconvert.add(Leadconvert);
}
if (!MassLeadconvert.isEmpty())
{
List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
}
}
}