Yes and we resolved this by creating an Apex class for REST call. Sample code is this -
@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>
This test will give you around 93% of coverage.
@isTest
public class RestLeadConvertTest{
static testMethod void testHttpGet() {
Lead l = new Lead();
l.FirstName = 'First';
l.LastName = 'Last';
l.Company = 'Unit Test';
insert l;
Test.startTest();
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
req.requestURI = '/Lead/' + l.Id;
req.httpMethod = 'GET';
RestContext.request = req;
RestContext.response= res;
RestLeadConvert.doGet();
Test.stopTest();
}
}
Hope this helps!
Check out Salesforce online training and become certified.
Thanks!