Thursday, February 19, 2015

Salesforce APEX - how to process more than 10000 rows in VF/Apex using Queueable interface

A great improvement by salesforce by adding feature like Queueable Interface


Using salesforce Queueable interface you can execute, 
you can create up to 50 asynchronous jobs, 
each with 10000 DML rows limit.
 
List<String> lstVal1 = new List<String>(); 
List<String> lstVal2 = new List<String>(); 
 
ID jobID1 = System.enqueueJob(new AsyncExecutionExample(lstVal1));
ID jobID2 = System.enqueueJob(new AsyncExecutionExample(lstVal2));
 
Set<Id> lstJbIds = new  Set<Id>();
lstJbIds.add(jobID1);
lstJbIds.add(jobID2);
 
// now track jobs status using following query from Visualforce page,
// use action poller.
// this is a great improvement from salesforce.com 
/// 
List<AsyncApexJob> jobInfo = 
    [SELECT Status,NumberOfErrors FROM AsyncApexJob WHERE Id in:lstJbIds];
 
 
------------------------------------------------------------------------------------------------------------
public class AsyncExecutionExample implements Queueable {
 
List<String> recordsList = null; 
 
public AsyncExecutionExample(List<String> listParam){
 this.recordsList = listParam;
} 
 
public void execute(QueueableContext context) {
   // process recrdsList here
} 
 
}

No comments:

Post a Comment