I am trying to update user records using batch and I am getting this error
Too many queueable jobs added to the queue: 2
I found out that the batch update is triggering triggers on the user and one such trigger is using enqueue method. The enqueued method is using a future method to update contact records and there are no enqueued jobs in any other trigger.
So my question as I am enqueuing only one class why I am getting this error when I am trying to update ures records?
This is the trigger
if(trigger.isAfter){
if(trigger.isUpdate){
System.enqueueJob(new GlobalPRM_UserTriggerHelper(Trigger.New, Trigger.oldMap));
}
}
Best Answer
See: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm
It means that the trigger, that calls System.enqueueJob, can be run twice in one transaction.