Advertisement
Guest User

Untitled

a guest
May 31st, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. global class BatchUpdate implements Database.Batchable<sObject>,Database.Stateful {
  2.  
  3. global final String Query;
  4. public Integer total=0;
  5. global BatchUpdate(String q) {
  6. Query=q;
  7. }
  8.  
  9.  
  10. global Database.QueryLocator start(Database.BatchableContext BC){
  11. return Database.getQueryLocator('SELECT id,b.LastModifiedDate from Base_Catalogue__c b');
  12. }
  13.  
  14. global void execute(Database.BatchableContext BC, list<sObject> scope){
  15.  
  16.  
  17. List<Base_Catalogue__c> bc1 = new List<Base_Catalogue__c>();
  18. List<BC_Count__c> count = [select BC_count_AP08__c from BC_Count__c];
  19. system.debug('The total count records from the Ap08 server: '+ count);
  20.  
  21. system.debug('Start of the program');
  22. for (sObject s : scope) {
  23. Base_Catalogue__c bc2 =(Base_Catalogue__c)s;
  24. DateTime d=bc2.LastModifiedDate;
  25. Date lastdate = date.newinstance(d.year(), d.month(), d.day());
  26. system.debug('Hi2::'+lastdate);
  27.  
  28. DateTime dT = System.Today();
  29. Date today = date.newinstance(dT.year(), dT.month(), dT.day());
  30. system.debug('Hi3:::'+today);
  31.  
  32. if(lastdate==today){
  33. system.debug('check');
  34. bc2.Check__c=true;
  35. total++;
  36.  
  37. }
  38. else
  39. {
  40. bc2.Check__c=false;
  41. }
  42. bc1.add(bc2);
  43.  
  44. system.debug('The total count records from the Ap08 server: '+ count);
  45. for(BC_Count__c var: count)
  46. {
  47. var.BC_count_AP08__c = total;
  48. update var;
  49.  
  50. }
  51.  
  52. }
  53. update bc1;
  54.  
  55.  
  56. }
  57. global void finish(Database.BatchableContext BC)
  58. {
  59. System.debug(LoggingLevel.Info, 'Your info');
  60. system.debug('COUNT::::'+total);
  61. if(!Test.isRunningtest()){
  62. //Updating all the Detail object records to point to Active Base Catalogue
  63. UpdateDetailReference udr = new UpdateDetailReference();
  64. Database.executebatch(udr,200);
  65. }
  66.  
  67. }
  68. }
  69.  
  70. global class BatchUpdate implements Database.Batchable<sObject>,Database.Stateful {
  71.  
  72. global final String Query;
  73. public Integer total=0;
  74. global BatchUpdate(String q) {
  75. Query=q;
  76. }
  77.  
  78.  
  79. global Database.QueryLocator start(Database.BatchableContext BC){
  80. return Database.getQueryLocator('SELECT id,b.LastModifiedDate from Base_Catalogue__c b');
  81. }
  82.  
  83. global void execute(Database.BatchableContext BC, list<sObject> scope){
  84.  
  85.  
  86. List<Base_Catalogue__c> bc1 = new List<Base_Catalogue__c>();
  87. system.debug('Start of the program');
  88. for (sObject s : scope) {
  89. Base_Catalogue__c bc2 =(Base_Catalogue__c)s;
  90. DateTime d=bc2.LastModifiedDate;
  91. Date lastdate = date.newinstance(d.year(), d.month(), d.day());
  92. system.debug('Hi2::'+lastdate);
  93.  
  94. DateTime dT = System.Today();
  95. Date today = date.newinstance(dT.year(), dT.month(), dT.day());
  96. system.debug('Hi3:::'+today);
  97.  
  98. if(lastdate==today){
  99. system.debug('check');
  100. bc2.Check__c=true;
  101. total++;
  102.  
  103. }
  104. else
  105. {
  106. bc2.Check__c=false;
  107. }
  108. bc1.add(bc2);
  109.  
  110. }
  111. update bc1;
  112.  
  113.  
  114. }
  115. global void finish(Database.BatchableContext BC)
  116. {
  117. List<BC_Count__c> count = [select BC_count_AP08__c from BC_Count__c];
  118. for(BC_Count__c var: count) {
  119. var.BC_count_AP08__c = total;
  120. }
  121. update count;
  122. system.debug('The total count records from the Ap08 server: '+ count);
  123. System.debug(LoggingLevel.Info, 'Your info');
  124. system.debug('COUNT::::'+total);
  125. if(!Test.isRunningtest()){
  126. //Updating all the Detail object records to point to Active Base Catalogue
  127. UpdateDetailReference udr = new UpdateDetailReference();
  128. Database.executebatch(udr,200);
  129. }
  130.  
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement