function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pradyprady 

Apex scheduler

Hi,

 

On researching on apex scheduler to for scheduling a class for every 10 or 15 mins we would need to write the schedule code in the system log.

 YourScheduleClass c = new YourScheduleClass();
String sch = '0 0 * * * ?';
System.schedule('Schedule Job1', sch, c);

YourScheduleClass c = new YourScheduleClass();
String sch = '0 10 * * * ?';
System.schedule('Schedule Job2', sch, c);

YourScheduleClass c = new YourScheduleClass();
String sch = '0 20 * * * ?';
System.schedule('Schedule Job3', sch, c);

YourScheduleClass c = new YourScheduleClass();
String sch = '0 30 * * * ?';
System.schedule('Schedule Job4', sch, c);

 Would these entries be an one time job on production env? Would it affect anything if i edit/change the times later?

kiranmutturukiranmutturu

if these jobs are scheduled once and you are trying to edit na then it will give you an error saying that scheduled jobs cant be edit ...then first u need to delete the current running jobs and create the new one.......other wise create the schedule string dynamically with local varibales... then u can do the same in the prod also.. but with static values like '0 10 ....' this u cant alert in the prod environment.....

pradyprady

where would i create the local variable? in the system logs?

kiranmutturukiranmutturu

not in system logs .. create a method to construct the string to schedule the class....for that accept the params as arguements

public void toschedule(string first,string second,string third.....){

   

    then ur final string would be

 

string str = 'fisrt, second, ......';

 

sys.schedule........

 

}

 

then in system log...

create the instance of the class and call the method with your respective values as arguments...hope you got it now