You need to sign in to do that
Don't have an account?
Orkhan Shukurov
scheduled apex job
I need a scheduled apex job for field update. I have the following code but it doesn't work. Any ideas about what could be the problem?
global class ReportStatusNotification implements Schedulable {
public void execute(SchedulableContext ctx) {
List<Project__c> projs = new List<Project__c>();
for(Project__c p : [SELECT Last_Status_Report__c, Report_Status_Indicator__c FROM Project__c]){
if (p.Last_Status_Report__c.month() == Date.Today().month()) {
p.Report_Status_Indicator__c = 'Green';
} else {
p.Report_Status_Indicator__c = 'Red';
}
projs.add(p);
}
update projs;
}
ReportStatusNotification m = new ReportStatusNotification();
String sch = '0 0 0 5-31 * ?';
String jobID = system.schedule('ReportStatusNotification', sch, m);
}
global class ReportStatusNotification implements Schedulable {
public void execute(SchedulableContext ctx) {
List<Project__c> projs = new List<Project__c>();
for(Project__c p : [SELECT Last_Status_Report__c, Report_Status_Indicator__c FROM Project__c]){
if (p.Last_Status_Report__c.month() == Date.Today().month()) {
p.Report_Status_Indicator__c = 'Green';
} else {
p.Report_Status_Indicator__c = 'Red';
}
projs.add(p);
}
update projs;
}
ReportStatusNotification m = new ReportStatusNotification();
String sch = '0 0 0 5-31 * ?';
String jobID = system.schedule('ReportStatusNotification', sch, m);
}
Updated code:
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
All Answers
Try replacing below line of code
with
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
What does it mean?
Updated code:
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal