我们必须通过REST -OAuth调用将潜在客户转换为帐户。我们能够创建,更新(编辑)和详细信息引导字段,但无法转换它们。
我们发现通过SOAP API可以实现相同的功能,但我们只关注REST OAuth。
答案 0 :(得分:10)
是的,我们通过为REST调用创建Apex类来解决这个问题。示例代码是这个 -
@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;
}
}
您可以通过
使用此调用<Your Instance URL>/services/apexrest/Lead/<LeadId>
此测试将为您提供约93%的报道。
@isTest
public class RestLeadConvertTest{
static testMethod void testHttpGet() {
Lead l = new Lead();
l.FirstName = 'First';
l.LastName = 'Last';
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();
}
}