Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global class updateAllOpptoday1 implements Database.Batchable<SObject>, Database.Stateful {
- Schema.DescribeFieldResult fieldResult = opportunity.StageName.getDescribe();
- global List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
- system.debug(ple.size());
- global Database.QueryLocator start(Database.BatchableContext BC)
- {
- String query = 'Select Id, Name, Stage_change_reminder_count__c,StageName From Opportunity WHERE StageName in:ple and Last_Activity_Age__c >=12 ';
- // added below line because Last_Activity_Age__c should be >=12 which we cnt do inside test class
- if(test.isRunningTest())
- {
- Query = 'Select Id, Name, Stage_change_reminder_count__c,StageName From Opportunity WHERE StageName = 'Qualification'OR'Needs Analysis'OR'Value Proposition'';
- }
- system.debug(query);
- return Database.getQueryLocator(query);
- }
- global void execute(Database.BatchableContext BC, List<SObject> scope) {
- for(Opportunity obj : (Opportunity[]) scope) {
- if(obj.Stage_change_reminder_count__c != Null) {
- obj.Stage_change_reminder_count__c = obj.Stage_change_reminder_count__c + 1;
- } else
- obj.Stage_change_reminder_count__c = 0;
- }
- system.debug('list to be updated size :: ' + scope.size());
- if(!scope.isEmpty())
- {
- update scope;
- }
- }
- global void finish(Database.BatchableContext BC){
- }
- }
- global class updateAllOpptoday1 implements Database.Batchable<SObject>, Database.Stateful {
- global Database.QueryLocator start(Database.BatchableContext BC)
- {
- Schema.DescribeFieldResult fieldResult = opportunity.StageName.getDescribe();
- List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
- system.debug(ple.size());
- String query;
- if (!test.isRunningTEst())
- {
- query = 'Select Id, Name, Stage_change_reminder_count__c,StageName From Opportunity WHERE StageName in:ple and Last_Activity_Age__c >=12 ';
- }
- else
- {
- // added below line because Last_Activity_Age__c should be >=12 which we cnt do inside test class
- Query = 'Select Id, Name, Stage_change_reminder_count__c,StageName From Opportunity WHERE StageName = 'Qualification'OR'Needs Analysis'OR'Value Proposition'';
- }
- system.debug(query);
- return Database.getQueryLocator(query);
- }
- }
Add Comment
Please, Sign In to add comment