• Deal and Deals
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi guys,

I am having difficulties finding way to solve the issue that one of my trigger actions triggers another action, it throws the AsyncException.

Here is my Trigger, it will trigger before an account is inserted into the object:
trigger createaccount on object(before insert) {
    if (Trigger.isBefore && Trigger.isInsert) {
        createaccountrec.onBeforeInsert(Trigger.new);
    }
}
The trigger calls the method that invokes another action that calls and gets data from API
private static void AccHandler(String accdomain) {
                Http http = new Http();
                HttpRequest request = new HttpRequest();
                request.setEndpoint('api request link');
                request.setHeader('Authorization info');
                request.setMethod('GET');
                HttpResponse response = http.send(request);
                Map<String, Object> res = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
                Map<String, Object> var = (Map<String, Object>) res.get(part here);
                String companyName = (String) var.get(field here); 
                Account newAccount = new Account();
                newAccount.Name = companyName;
     	        insert newAccount;
            }
        }
    }
    
    public static void createaccountrec(list<object_name> recAccs) {
        for (object_name recAcc: recAccs) {
            if (!Test.isRunningTest()) {
				AccHandler(recAcc.field);
            }
        }
    }
How can I solve the Assync Exception issue here? I try to put @future(callout = true) but it doesn't work either. This code runs normally if I try to insert account manually, however it will throw the exception if any action, integration try to insert account.

Thank you so much.