document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2. * @author : Sumitkumar Shingavi (sumi.shingavi@gmail.com)
  3. * @created_date : 04/18/2015
  4. * @description : Apex Schedulable batch class to Process Account records
  5. */
  6. global with sharing class AccountBatch implements Schedulable, Database.Batchable<sObject>, Database.Stateful, Database.AllowsCallouts {
  7.  
  8. //Variable Section
  9. global FINAL String strQuery;
  10. global AccountBatch(String strQuery) { this.strQuery = strQuery; }
  11.  
  12. //Batch Start method
  13. global Database.QueryLocator start(Database.BatchableContext BC) {
  14. return Database.getQueryLocator(strQuery);
  15. }
  16.  
  17. //Batch Execute method calls ProcessAccounts method
  18. global void execute(Database.BatchableContext BC, List<sObject> lScope) {
  19. System.debug(LoggingLevel.INFO, '== lScope size ==' + lScope.size());
  20.  
  21. List<Account> lAccounts = (List<Account>) lScope;
  22. if(!lAccounts.isEmpty()) { processAccounts(lAccounts); }
  23. }
  24.  
  25. //Batch Finish method for after exeutetion of batch work
  26. global void finish(Database.BatchableContext BC) {
  27. //Do nothing if this is a single batch
  28.  
  29. //In case: If you want to serial batching then call next batch from this method
  30. }
  31.  
  32. /*
  33. * @auther : Sumitkumar Shingavi (sumi.shingavi@gmail.com)
  34. * @date : 04/18/2015
  35. * @description : Apex method for Processing Accounts
  36. * @parameters : List of Account records
  37. * @returns : Nothing
  38. */
  39. private void processAccounts(List<Account> lAccounts) {
  40. System.debug(LoggingLevel.INFO, '== lAccounts =='+ lAccounts);
  41.  
  42. //Do Processing on Records coming in lAccounts
  43. }
  44.  
  45. //Method which schedules the AccountBatch
  46. global void execute(SchedulableContext sc) {
  47. String strQuery = 'SELECT Id, Name FROM Account ORDER BY Name';
  48. AccountBatch abInstance = new AccountBatch(strQuery);
  49. ID batchprocessid = Database.executeBatch(abInstance, 50);
  50. }
  51. }
');