我在从移动应用程序(使用适用于 iOS 的 salesforce 移动 SDK 开发的混合远程应用程序)进行 Apex REST 网络服务调用时遇到“不允许调用循环”的问题,这反过来又调用了外部网络服务。
这个用例是关于调用 Authorise.net 进行支付处理。
用户->登录->信用卡详细信息->restful apex 调用-forceTk-> http 调用付款(在 restful apex 方法内)->用结果更新用户
这是代码
身份验证:
var forceTKClient;
cordova.require("salesforce/plugin/oauth").authenticate(functionSuccessCallBack, functionErrorCallBack);
function functionSuccessCallBack (creds) {
var apiVersion = "v28.0";
forceTKClient = new forcetk.Client(creds.clientId, creds.loginUrl, null, cordova.require("salesforce/plugin/oauth").forcetkRefresh);
forceTKClient.setSessionToken(creds.accessToken, apiVersion , creds.instanceUrl);
forceTKClient.setRefreshToken(creds.refreshToken);
forceTKClient.setUserAgentString(creds.userAgent);
}
REST 网络服务
/*************************************************************************
* HttpPost method
**************************************************************************/
@HttpPost
global static REST_ProcessOrder_V1.ProcessOrderResponse doPost
(REST_ProcessOrder_V1.ProcessOrderRequest OrderRequest) {
//http callout to payment gateway
//post call code to update database with transaction details
}
来自客户端的 REST 调用
forceTKClient.apexrest('/v1/orders/' ,
function(data, textStatus, jqXHR){
//process = data;
console.log("****Response Success : "+JSON.stringify(data));
scope.$apply(defered.resolve(data));
}
提前感谢您的帮助!
我有类似的情况但更简单 - 外部系统 A 发送 REST API 请求在 Salesforce 中创建记录,在对象上执行触发器,执行未来方法以向另一个外部系统 B 发出标注。这个未来方法失败并显示
System.CalloutException: Callout loop not allowed
错误。
我的解决方案是从 Scheduled 类中进行标注。因此,我没有执行未来的方法,而是安排了从当前时间开始的 2 秒内执行的类。