本文介绍了Salesforce 中是否有任何 REST 服务可用于将潜在客户转换为客户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们必须通过 REST -OAuth 调用将潜在客户转换为帐户.我们能够创建、更新(编辑)和详细信息潜在客户字段,但无法转换它们.
We have to convert Leads to accounts via REST -OAuth calls. We are able to create, update(Edit) and Detail Lead fields but not able to convert them.
我们发现通过 SOAP API 也可以实现相同的功能,但我们仅遵循 REST OAuth.
We found the same is possible via SOAP API but we are following REST OAuth only.
推荐答案
是的,我们通过为 REST 调用创建 Apex 类解决了这个问题.示例代码是这样的 -
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;
}
}
您可以通过
<Your Instance URL>/services/apexrest/Lead/<LeadId>
此测试将为您提供大约 93% 的覆盖率.
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();
}
}
这篇关于Salesforce 中是否有任何 REST 服务可用于将潜在客户转换为客户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!