About this question
I've been looking for similar questions, but none of them applies to my scenario, so I'd be grateful if you can explain to me why my logic is failing, and what I can do in order to fix it.
I want to run every month a logic on Account records (>50k) : BATCHS
This logic will create X events on each account : Event Trigger For new Events, I need to sync the data with other system : @future method So, since Batchs cannot call other future methods, I decided to implement the @future logic inside a Queueable class.
Here is a snippet:
Batch
global class BATCH_GeneradorEventos implements Database.Batchable{
...
global void execute(Database.BatchableContext BC, Listscope) {
...
insert evs;
}
...
}
Event trigger
ID jobID = System.enqueueJob(new EventQueueableJob(Trigger.newMap.keySet()));
Queuable class
public class EventQueueableJob implements Queueable, Database.AllowsCallouts
{
...
public void execute(QueueableContext context)
{
// future methods and logic
}
}
The error that I'm getting is:
"Too many queueable jobs added to the queue: 2"
and it's giving me for every SerialBatch.
Is it because I'm doing an enqueueJob for every iteration of the Batch? If so, how can I fix/remodel it?