+ Start a Discussion
anil Kumaranil Kumar 

Batch job schedule

Hi All,

I have requirement where i need schedule batch job 4 times in day. this are the timinings 1AM EST, 10 AM EST, 3PM EST, 8PM EST. I have schedule this using cron expression in dev console. i have prepared script below, please advise is this correct.


className c = new className();
String sch = '0 0 1,10,15,20 * * *';
system.schedule('Four times in day ', sch, c);

Thanks,
Anil Kumar
Best Answer chosen by anil Kumar
mritzimritzi
From Developer Console -> Debug -> Open Execute Anonymous Window

Type following thing and click execute.
//change this with actual class name
MySchedulableClass schClass = new MySchedulableClass();
//runs at time mentioned in variable name
String time1am = '0 0 1 1/1 * ? *';
String time10am = '0 0 10 1/1 * ? *';
String time3pm = '0 0 15 1/1 * ? *';
String time8pm = '0 0 20 1/1 * ? *';
System.schedule('MySchedulableClass 1am', time1am, schClass);
System.schedule('MySchedulableClass 10am', time10am, schClass);
System.schedule('MySchedulableClass 3pm', time3pm, schClass);
System.schedule('MySchedulableClass 8pm', time8pm, schClass);

After executing this code block.
Go to Setting/Setup -> Scheduled Jobs
You can see these 4 jobs scheduled with necessary details.
(This will run everyday from the day it's scheduled)

Please mark this as Best Answer, if this solves your problem.

All Answers

mritzimritzi
From Developer Console -> Debug -> Open Execute Anonymous Window

Type following thing and click execute.
//change this with actual class name
MySchedulableClass schClass = new MySchedulableClass();
//runs at time mentioned in variable name
String time1am = '0 0 1 1/1 * ? *';
String time10am = '0 0 10 1/1 * ? *';
String time3pm = '0 0 15 1/1 * ? *';
String time8pm = '0 0 20 1/1 * ? *';
System.schedule('MySchedulableClass 1am', time1am, schClass);
System.schedule('MySchedulableClass 10am', time10am, schClass);
System.schedule('MySchedulableClass 3pm', time3pm, schClass);
System.schedule('MySchedulableClass 8pm', time8pm, schClass);

After executing this code block.
Go to Setting/Setup -> Scheduled Jobs
You can see these 4 jobs scheduled with necessary details.
(This will run everyday from the day it's scheduled)

Please mark this as Best Answer, if this solves your problem.
This was selected as the best answer
Akshay_DhimanAkshay_Dhiman
Hi Anil,

    Here is a solution to your Problem.
    
    className c = new className();
    String sch =  '0 0 1,10,15,20 * * ?'; 
    system.schedule('Four times in day ', sch, c);


I hope it will help you.
Please select this as Best Answer so that other's also get help from this.
 
Thank You
Akshay
anil Kumaranil Kumar
Hi Mritzi,

Thank you for the replay..

Could you please explain me what mean by 1/1 in the below expression. Also can we keep ? at 6 position insted of 5th position.

Thanks,
Anil Kumar
mritzimritzi
1/1 is for day.
That ensures that batch executes every day
1/1 -> first 1 means starting date, second 1 means increament.
Strating from 1st of every month, keep increamenting by 1.

Each value is meant for specific purpose
First parameter is for second, second for minute, third for hours, fourth for day and so on...
You can find more info on the web about Salesforce cron expression.
Hope this helps.

Please mark relevant answer as correct, if your problem has been resolved.