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
Renan Freitas 4Renan Freitas 4 

API REST CONVERT LEAD IN ACCOUNT

Hello guys I'm trying to convert a lead into account via REST API using the status field, will someone have an example code or reference link for which I can base thanks in advance
Raj VakatiRaj Vakati


@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 below call 

 
<Your Instance URL>/services/apexrest/Lead/<LeadId>


 
Renan Freitas 4Renan Freitas 4
Thanks Raj V, I was using this example in case I'll need to use a trigger since the conversion process I'm using is based on status?
Renan Freitas 4Renan Freitas 4
Thanks Raj V, I was using this example in case I'll need to use a trigger since the conversion process I'm using is based on status?