2

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?

  • 1
    The SOAP API supports this with convertLead(), the REST API does not as of V32. You'll need an Apex REST service as answered by A-d below – cropredy Sep 22 '14 at 3:05
4

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.

| improve this answer | |
  • Thanks, looks like for some reason we don't have Apex available so I'll follow up with that, but I think this is the correct solution – Greg Hinch Sep 22 '14 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.