[SalesForce] How to convert a Lead via the REST API

Am a bit new to Salesforce, integrating with our existing systems which uses Python, so I'm making use of the simple_salesforce module. It's working great, except I cannot figure out how you convert a Lead to a Contact/Account via the API. Is there some endpoint to do this?

Best Answer

You can try using the answer in this Question

@RestResource(urlMapping='/Lead/*')
global with sharing class RestLeadConvert {            

@HttpGet
global static String doGet() {
    String ret = 'fail';
    RestRequest req = RestContext.request;
    RestResponse res = RestContext.response;
    String leadId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);              
    Database.LeadConvert lc = new Database.LeadConvert();
    lc.setLeadId(leadId);

    LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
    lc.setConvertedStatus(convertStatus.MasterLabel);           
    Database.LeadConvertResult lcr ;
    try{
        lcr = Database.convertLead(lc);
        system.debug('*****lcr.isSuccess()'+lcr.isSuccess());            
        ret = 'ok';
    }
    catch(exception ex){
        system.debug('***NOT CONVERTED**');           
    }
    return ret;
}
}

And use this as given in "Using Apex" section in the simple_salesforce module guide.

Related Topic