/*
* @author : Sumitkumar Shingavi (sumi.shingavi@gmail.com)
* @created_date : 04/18/2015
* @description : Apex Schedulable batch class to Process Account records
*/
global with sharing class AccountBatch implements Schedulable, Database.Batchable<sObject>, Database.Stateful, Database.AllowsCallouts {
//Variable Section
global FINAL String strQuery;
global AccountBatch(String strQuery) { this.strQuery = strQuery; }
//Batch Start method
global Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator(strQuery);
}
//Batch Execute method calls ProcessAccounts method
global void execute(Database.BatchableContext BC, List<sObject> lScope) {
System.debug(LoggingLevel.INFO, '== lScope size ==' + lScope.size());
List<Account> lAccounts = (List<Account>) lScope;
if(!lAccounts.isEmpty()) { processAccounts(lAccounts); }
}
//Batch Finish method for after exeutetion of batch work
global void finish(Database.BatchableContext BC) {
//Do nothing if this is a single batch
//In case: If you want to serial batching then call next batch from this method
}
/*
* @auther : Sumitkumar Shingavi (sumi.shingavi@gmail.com)
* @date : 04/18/2015
* @description : Apex method for Processing Accounts
* @parameters : List of Account records
* @returns : Nothing
*/
private void processAccounts(List<Account> lAccounts) {
System.debug(LoggingLevel.INFO, '== lAccounts =='+ lAccounts);
//Do Processing on Records coming in lAccounts
}
//Method which schedules the AccountBatch
global void execute(SchedulableContext sc) {
String strQuery = 'SELECT Id, Name FROM Account ORDER BY Name';
AccountBatch abInstance = new AccountBatch(strQuery);
ID batchprocessid = Database.executeBatch(abInstance, 50);
}
}