Good day Everyone,
I have a trigger that will call a Queueable. The process looks like this :
Trigger :
for(User userData : Trigger.new) {
if(Limits.getLimitQueueableJobs() - Limits.getQueueableJobs() > 0 && !Test.isRunningTest()) {
system.enqueueJob(new Assignment(userData));
} else {
System.debug('FUTURE LIMIT EXCEEDED');
}
}
and my Queueable looks like this :
public class Assignment implements Queueable, Database.AllowsCallouts {
// the constructor is parameter is used in execute method
public Assignment(User theUser) {
}
public void execute(QueueableContext context) {
// some process here
}
}
At the moment everything is working fine but what i'm trying to achieve is that the next Queueable will only run if the first Queueable is done running. What I am trying to achieve is something like a chaining Queueable. I did try to update my trigger to only call the Queueable once then I update my Queueable class to something like this :
Trigger :
system.enqueueJob(new Assignment(Trigger.new));
Queueable:
public class Assignment implements Queueable, Database.AllowsCallouts {
public List<User> allUserList = new List<User>();
// the constructor is parameter is used in execute method
public Assignment(List<User> userList) {
allUserList = userList;
}
public void execute(QueueableContext context) {
// some process here
// at the end of the execute method
allUserList.remove(0);
if(allUserList.size() > 0) {
system.enqueueJob(new Assignment(allUserList));
}
}
}
But when I update many data simultaneously, I encounter this error.
Too many queueable jobs added to the queue
Can you please give your idea what do I need, to do this ? Thank you.