Posted in Salesforce

Apex Flex Queues and Queueable Interface

If you want one process to complete before starting the next process since the 2nd process depends on the 1st process.

Apex Flex Queues

Salesforce allowed only to have 5 concurrent batches running and
adding the 6th concurrent batch would cause the “Attempted to schedule too many concurrent batch jobs” error.

With the introduction of the Apex Flex Queues, now developers are able to submit up to 100 batches concurrently in “Holding” status and
are also able to manage the order of the queued jobs in order to control which jobs are processed first.

If the Apex flex queue has the maximum number of 100 jobs,
Database.executeBatch throws a LimitException and doesn’t add the job to the queue.

When the system has enough resources, it takes the jobs at the top of the Apex Flex Queue and places those in the Batch Job Queue with the “Queued” status.
The system is able to process up to 5 jobs concurrently.

AsyncApexJob

There will be an impact to the existing queries on the AsyncApexJob object which filters records via the status field.
Earlier where queries that made use of statuses “Queued”, “Processing”, and “Preparing” would now have to also incorporate the new “Holding” status.

Eg: Select Id, Status From AsyncApexJob wHERE Status IN (‘Queued’, ‘Processing’, ‘Preparing’, ‘Holding’);

Queueable Interface

asynchronized job chaining , Like calling one batch from another.

System.enqueueJob() method

After completing the business logic requirements, Process 1 would add Process 2 to the queue from the execute() method of the Queueable class.
In order to do this the System.enqueueJob() method would be used.

Only one Asynchronized Job can be added from an executing job via the System.enqueueJob() method.

Advertisements
Posted in Salesforce

How to process more than 50 million records in batch

A batch class that uses Database.QueryLocator as the return type of start method or returns Database.getQueueryLocator() is capable of processing 50 million records.

What if you want to process more than 50 million records ?

We cannot process more than 50 million records i.e. if the start method passes more than 50 million records to scope of execute method then batch is immediately terminated.

In sort batch classes cannot process more than 50 million records it is terminated.