You can place up to 100 batch jobs in a holding status for future execution. When system resources become available, the jobs are taken from the top of the Apex flex queue and moved to the batch job queue. Up to five queued or active jobs can be processed simultaneously for each org. When a job is moved out of the flex queue for processing, its status changes from Holding to Queued. Queued jobs are executed when the system is ready to process new jobs.
Use this class’s methods to reorder your Holding jobs in the flex queue.
ID jobToMoveId = System.enqueueJob(new MyQueueableClass()); AsyncApexJob a = [SELECT Id FROM AsyncApexJob WHERE ApexClassId IN (SELECT Id from ApexClass WHERE NamespacePrefix = null AND Name = 'BatchJob')]); ID jobInQueueId = a.ID; Boolean isSuccess = FlexQueue.moveBeforeJob(jobToMoveId, jobInQueueId);
The following are methods for FlexQueue.
public static Boolean moveAfterJob(Id jobToMoveId, Id jobInQueueId)
Type: Boolean
public static Boolean moveBeforeJob(Id jobToMoveId, Id jobInQueueId)
Type: Boolean
public static Boolean moveJobToEnd(Id jobId)
Type: Boolean
public static Boolean moveJobToFront(Id jobId)
Type: Boolean