4

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
  • 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, 2014 at 3:05

2 Answers 2

5

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.

1
  • 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, 2014 at 9:16
1

Here is a class that exposes all the features of the Apex LeadConvert functionality.

https://github.com/bolaurent/salesforce_rest_leadconvert

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .