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
Sarma DuvvuriSarma Duvvuri 

Apex Class for Lead Conversion to the existing Account

Hi,

I am not able to update the contact details for existing account in Lead Conversion. Kindly help in this issue.

This is the code i am using.

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.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);
        }
    }
}
Vinod ChoudharyVinod Choudhary
Hi Sarma,

Hope this will help you.
https://salesforce.stackexchange.com/questions/4209/can-i-programmatically-merge-leads-to-existing-accounts

Thanks
Vinod
Colin KenworthyColin Kenworthy
Starting API v36.0 you should no longer use MasterLabel, your code could fail - use ApiName instead:
LeadStatus CLeadStatus = [SELECT Id, ApiName FROM LeadStatus WHERE isConverted=true Limit 1];
...
   Leadconvert.setConvertedStatus(CLeadStatus.ApiName);
...