• #36922
    Salesforce | Aman Aman #4
    Forcetalks

    How to convert lead using Salesforce Apex?

    How to convert lead using Salesforce Apex?

     

    #36923
    Salesforce | shariq shariq #1
    Forcetalks

    Lead myLead = new Lead(LastName = ‘Foo’, Company=’Foo Bar’);
    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());

    #37134
    Salesforce | Parul Parul #2
    Forcetalks

    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

Viewing 3 posts - 1 through 3 (of 3 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?