2

I am facing 'callout loop not allowed' issue while making a Apex REST webservice call from mobile app (Hybrid remote app developed using salesforce mobile SDK for iOS ) which in turn makes a callout to external webservice.

This use case is about making a call to Authorise.net for payment processing.

User->login->credit card details -> restful apex call - forceTk -> http callout to payment(within restful apex method)->update user with result

Here is the code

Authentication:

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 webservice

/*************************************************************************
* 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 call from client side

 forceTKClient.apexrest('/v1/orders/' ,
    function(data, textStatus, jqXHR){
        //process = data;
        console.log("****Response Success : "+JSON.stringify(data));
        scope.$apply(defered.resolve(data));
    }

Thanks in advance for your help!

Sourabh
  • 4,545
  • 11
  • 39
  • 45
  • From what I understand salesforce wants to avoid callout loop from one salesforce org to another salesforce org. In my case there is no second org. its only the mobile client who is accessing the rest methods – Sourabh May 14 '14 at 03:39

1 Answers1

0

I have the similar situation but simpler - external system A sends REST API request to create a record in Salesforce, trigger is executed on the object, future method is executed to make a callout to another external system B. This future method fails with the System.CalloutException: Callout loop not allowed error. The solution for me was to make this callout from Scheduled class. So instead of executing future method, I scheduled class to be executed in 2 seconds from current time.

Andrii Muzychuk
  • 1,151
  • 3
  • 20
  • 28