function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Guna P 3Guna P 3 

Is there REST api available to convert lead to contact?

I'm using Developer Edition in which I coud see conver option for leads. I want to convert the leads to contacts/accounts using REST api.
How to accomlish this in REST api.

Thanks,
Guna
NagendraNagendra (Salesforce Developers) 
Hi Guna,

May I suggest you please try this sample code and tweak it as per your requirement to implement lead conversion through REST Call - pls check if that can help:
@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 you can use this call by
<Your Instance URL>/services/apexrest/Lead/<LeadId>
​
Hope this helps.

Thanks,
Nagendra
 
Guna P 3Guna P 3
Hi Nagendra,

Thanks for the quick response.

I've tried with this URL: https://ap5.salesforce.com/services/apexrest/Lead/00Q7F000008F5siUAC
Method: POST
Body: {"IsConverted":true}

And I've got following response:
[{"errorCode":"NOT_FOUND","message":"Could not find a match for URL"}]

Please let me know if any documentation regarding this REST api for appropriate URL, HTTP Method and Post body.

Thanks,
Guna
Cosimo ElefanteCosimo Elefante
In the example is used the GET method "doGet()"