function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Peter Thompson 7Peter Thompson 7 

Lead created by LMA causes Trigger failure "System.CalloutException: Callout loop not allowed"

​I have been hitting this error with our Trigger implementation and I could use some help in figuring out how to deal with it.

We have a managed package that we expose through the AppExchange
  • Someone installs, we get a lead created by the License Management Application within our org.
  • I have Lead Trigger that runs  "After Create"
  • The trigger is queueing an @future task to callout to “our service”
However, the LMA seems to be running in the context of a user from a different organization, and the @future call that I have is also running in this same user context.
The result is an exception:
Apex script unhandled exception by user/organization: 005x0000000xxxx/00Dx0000000xxxx
Failed to invoke future method 'public static void Report(String, String)' on class 'TriggerCallback' for job id '707i00000xxxxxx'
caused by: System.CalloutException: Callout loop not allowed
Class.TriggerCallback.Report: line 109, column 1

From my reaing online,it seems the callout is failing because it is running as the user in the LMA, which is not a user in out organization.  

Can I ignore this? Are the other scenarios that my trigger will run in the context of an external user?
Can I detect this and suppress this without trapping ALL CalloutExceptions?

Any suggestions would be much appreciated
Vijay AdusumilliVijay Adusumilli
It will be helpful to debug if you post your trigger code.
Peter Thompson 7Peter Thompson 7
Here is the code (simplified)
trigger MyLeadCreate on Lead (after insert) 
	for (Lead lead : { 
public class TriggerCallback { 
	public static void OnLeadCreate(Lead data){ 
		string payload = GeneratePayload(data); 
	public static void Report(string sPayload) { 
		HttpRequest req = new HttpRequest(); 
		req.setHeader('Content-Type', 'application/json'); 
		Http http = new Http(); 
		HTTPResponse res = http.send(req); 
		integer statusCode = res.getStatusCode(); 
it is throwing when sending the request.

To be clear, the code works fine in other scenarios, just when the lead is created by the LMA
Vijay AdusumilliVijay Adusumilli
Here is just a pointer that you may want to look into  - make sure that your LMA is not inadvertantly inserting more than one lead at the same time.
Mitesh SuraMitesh Sura
If you have enabled "PageReference getContent() and getContentAsPDF() Methods Treated as Callouts" criticle update, follow this thread:
Dippan PatelDippan Patel
Hi Peter, 

I am facing the same issue. Lead created by LMA is causing my trigger to fail with the error: Callout loop not allowed.
Did you find a solution to your question above? 

Thank you.