You need to sign in to do that
Don't have an account?
Nandhini S 3
Clarification on scheduler class
Hi Guys,
I have a scheduler class, there is a method inside the class which has system.schedule to schedule that scheduler class.
I don't understand how this works.
global class testSchedule implements Schedulable {
public static String sched;
public testSchedule (){
List<Period> fiscalYear = [SELECT StartDate FROM Period WHERE Type = 'Year' AND StartDate <= TODAY AND EndDate >= TODAY LIMIT 1];
String startDay = String.valueOf(fiscalYear[0].StartDate.day());
String startMonth = String.valueOf(fiscalYear[0].StartDate.month());
//Every Start Date of Fiscal Year period.
sched = '0 00 00 ' + startDay + ' ' + startMonth + ' ?';
}
global static String scheduleMe() {
testSchedule SC = new testSchedule ();
return System.schedule('Test Job', sched, SC);
}
global void execute(SchedulableContext SC) {
Id batchJobId = Database.executeBatch(new testBatch(true, false));
}
}
I have a scheduler class, there is a method inside the class which has system.schedule to schedule that scheduler class.
I don't understand how this works.
global class testSchedule implements Schedulable {
public static String sched;
public testSchedule (){
List<Period> fiscalYear = [SELECT StartDate FROM Period WHERE Type = 'Year' AND StartDate <= TODAY AND EndDate >= TODAY LIMIT 1];
String startDay = String.valueOf(fiscalYear[0].StartDate.day());
String startMonth = String.valueOf(fiscalYear[0].StartDate.month());
//Every Start Date of Fiscal Year period.
sched = '0 00 00 ' + startDay + ' ' + startMonth + ' ?';
}
global static String scheduleMe() {
testSchedule SC = new testSchedule ();
return System.schedule('Test Job', sched, SC);
}
global void execute(SchedulableContext SC) {
Id batchJobId = Database.executeBatch(new testBatch(true, false));
}
}
After you implement a class with the Schedulable interface, use the System.Schedule method to execute it. The System.Schedule method uses the user's timezone for the basis of all schedules, but runs in system mode—all classes are executed, whether or not the user has permission to execute the class.
See more info here https://developer.salesforce.com/docs/atlas.en-us.224.0.apexcode.meta/apexcode/apex_scheduler.htm
Thank you