Catch Apex Callout Loop not Allowed

Getting the following error: Apex Callout Loop not Allowed when you are doing a callout to the same Salesforce org and then calling out to another external service.

In this case I was doing a callout to the same salesforce org and then doing a callout to the my logging service.

RestRequest request = RestContext.request;
Map requestHeaders = request.headers;
if (requestHeaders.containsKey('Sfdc-Stack-Depth') && '1'.equals(requestHeaders.get('Sfdc-Stack-Depth'))){
      System.debug('Do not calllout as it will cause a callout loop error');
} 

Further you can write these values to a custom object and have a scheduler or workflow run to do the callout.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s