Guest User

Untitled

a guest
Jan 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. global class updateAllOpptoday1 implements Database.Batchable<SObject>, Database.Stateful {
  2.  
  3. Schema.DescribeFieldResult fieldResult = opportunity.StageName.getDescribe();
  4. global List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
  5. system.debug(ple.size());
  6.  
  7. global Database.QueryLocator start(Database.BatchableContext BC)
  8. {
  9. String query = 'Select Id, Name, Stage_change_reminder_count__c,StageName From Opportunity WHERE StageName in:ple and Last_Activity_Age__c >=12 ';
  10.  
  11. // added below line because Last_Activity_Age__c should be >=12 which we cnt do inside test class
  12. if(test.isRunningTest())
  13. {
  14. Query = 'Select Id, Name, Stage_change_reminder_count__c,StageName From Opportunity WHERE StageName = 'Qualification'OR'Needs Analysis'OR'Value Proposition'';
  15. }
  16.  
  17. system.debug(query);
  18. return Database.getQueryLocator(query);
  19. }
  20.  
  21. global void execute(Database.BatchableContext BC, List<SObject> scope) {
  22. for(Opportunity obj : (Opportunity[]) scope) {
  23. if(obj.Stage_change_reminder_count__c != Null) {
  24. obj.Stage_change_reminder_count__c = obj.Stage_change_reminder_count__c + 1;
  25. } else
  26. obj.Stage_change_reminder_count__c = 0;
  27. }
  28. system.debug('list to be updated size :: ' + scope.size());
  29. if(!scope.isEmpty())
  30. {
  31. update scope;
  32. }
  33. }
  34.  
  35. global void finish(Database.BatchableContext BC){
  36. }
  37. }
  38.  
  39. global class updateAllOpptoday1 implements Database.Batchable<SObject>, Database.Stateful {
  40.  
  41. global Database.QueryLocator start(Database.BatchableContext BC)
  42. {
  43. Schema.DescribeFieldResult fieldResult = opportunity.StageName.getDescribe();
  44. List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
  45. system.debug(ple.size());
  46.  
  47. String query;
  48.  
  49. if (!test.isRunningTEst())
  50. {
  51. query = 'Select Id, Name, Stage_change_reminder_count__c,StageName From Opportunity WHERE StageName in:ple and Last_Activity_Age__c >=12 ';
  52. }
  53. else
  54. {
  55. // added below line because Last_Activity_Age__c should be >=12 which we cnt do inside test class
  56. Query = 'Select Id, Name, Stage_change_reminder_count__c,StageName From Opportunity WHERE StageName = 'Qualification'OR'Needs Analysis'OR'Value Proposition'';
  57. }
  58.  
  59. system.debug(query);
  60. return Database.getQueryLocator(query);
  61. }
  62. }
Add Comment
Please, Sign In to add comment