Thursday, 4 December 2014

How to limit the scope in batch class

While executing the batch, you can limit the scope of the batch class.

Example:

Below is the sample batch class

Batch Class:

global class BatchClass implements  Database.Batchable<Sobject>
{
                global Database.QueryLocator start(Database.BatchableContext BC){
                }
                global void execute(Database.BatchableContext BC, List<case> scope){
                }
                global void finish(Database.BatchableContext BC){
                }
}

While calling the batch class in another class

BatchClass exter = new BatchClass();
database.executebatch(exter,1);

In the execute method , we can give the parameter to limit the scope.