I have a few open read/write number fields that are being updated through counters in a workflow. New activity comes in, the field will be increased by one. But I want to reset the counts every week.
So I'm using a scheduler class:
global class Reset7DayActivityCounterScheduler implements Schedulable{
global void execute(Schedulablecontext sc)
{
Reset7DayActivityCountersBatch lead = new Reset7DayActivityCountersBatch();
Database.executeBatch(lead,200);
}
}
And a batch class:
global class Reset7DayActivityCountersBatch implements Database.Batchable<sObject>{
global Database.querylocator start(Database.BatchableContext BC){
String query = 'SELECT Id, '
+ 'of_Calls_Last_7_Days__c, '
+ 'of_Emails_Sent_Last_7_Days__c, '
+ 'of_Replies_Last_7_Days__c '
+ 'FROM Lead';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Lead> scope){
for(Lead ob1 : scope){
ob1.of_Calls_Last_7_Days__c = 0;
ob1.of_Emails_Sent_Last_7_Days__c = 0;
ob1.of_Replies_Last_7_Days__c = 0;
}
update scope;
}
global void finish(Database.BatchableContext BC){
}
}
Then I'm using "Schedule Apex" to run the thing. Though I'm seeing no changes to the aforementioned fields. They still maintain their previous numbers.
Not sure what to do here.