Activity Forums Salesforce® Discussions How we Convert Lead through Salesforce Apex?

  • Parv Shekhar Singh

    Member
    May 31, 2018 at 10:52 am

    Hi Shubham,

    Here's the sample of code which you can use for conversion of Lead.

    Lead myLead = new Lead(LastName = 'Fry', Company='Fry And Sons');
    insert myLead;

    Database.LeadConvert lc = new Database.LeadConvert();
    lc.setLeadId(myLead.id);

    LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
    lc.setConvertedStatus(convertStatus.MasterLabel);

    Database.LeadConvertResult lcr = Database.convertLead(lc);
    System.assert(lcr.isSuccess());

  • Parul

    Member
    September 16, 2018 at 3:30 pm

    Public class LeadClass{
    public static void doConvert(Id leadId){

    Database.LeadConvert lc = new database.LeadConvert();
    lc.setLeadId(leadId);
    lc.setDoNotCreateOpportunity(True);

    LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
    lc.setConvertedStatus(convertStatus.MasterLabel);
    Database.LeadConvertResult lcr = Database.convertLead(lc);
    }
    }

     

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos