You need to sign in to do that
Don't have an account?

I am getting error while using the cron expression to run a apex class every 10 min.
String sch1 = '0 0/10 * 1/1 * ? *';
System.schedule('Scheduled Job 3', sch1, new myScheduleClass());
I generated the cron expression using tool cronmaker.
ERROR:System.StringException: Seconds and minutes must be specified as integers: 0 0/10 * 1/1 * ? *
System.schedule('Scheduled Job 3', sch1, new myScheduleClass());
I generated the cron expression using tool cronmaker.
ERROR:System.StringException: Seconds and minutes must be specified as integers: 0 0/10 * 1/1 * ? *
Below code can fulfill your requirements. Hope this will work for you.
global class ScheduleEveryMinutes implements Schedulable {
global void execute(SchedulableContext SC) {
AccountCountBatch countacc = new AccountCountBatch();
Database.executebatch(countacc);
// ScheduleEveryMinutes m = new ScheduleEveryMinutes();
//Integer sch = '0 */10 * ? * *';
// String jobID = system.schedule('Every 10 Minutes', sch, m);
// AccountCountBatch.startJob();
String day = string.valueOf(system.now().day());
String month = string.valueOf(system.now().month());
String hour = string.valueOf(system.now().hour());
String minute = string.valueOf(system.now().minute() + 10);
String second = string.valueOf(system.now().second());
String year = string.valueOf(system.now().year());
String strJobName = 'Job-' + second + '_' + minute + '_' + hour + '_' + day + '_' + month + '_' + year;
String strSchedule = '0 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
System.schedule(strJobName, strSchedule, new ScheduleEveryMinutes());
}
}
Please mark this as best answer if this solves your problem.
Thank you
Ajay Dubedi
All Answers
You don't need a tool for creating cron expresion. Cron expression should be in following format.
Seconds Minutes Hours Day_of_month Month Day_of_week optional_year
For example if you want to schedule it for every 10 minutes then it should be '0 10 * * * *'
if you want to schedule for 12 PM every day then it should be '0 0 12 * * ?'
I hope I've answered your query
Thanks
Manish
* denotes All Value
Execute below code in an anonymous block. This code will execute every 10 min entire day
String sch1 = '0 0 * * * ?';
String jobId = System.schedule(' - (Every 5min)', sch1, new myScheduleClass());
String sch3 = '0 10 * * * ?';
String jobId = System.schedule('(Every 10min)', sch2, new myScheduleClass());
String sch3 = '0 20 * * * ?';
String jobId = System.schedule('(Every 20min)', sch3, new myScheduleClass());
String sch4 = '0 30 * * * ?';
String jobId = System.schedule('(Every 30min)', sch4, new new myScheduleClass());
String sch5 = '0 40 * * * ?';
String jobId = System.schedule('(Every 40min)', sch5, new myScheduleClass());
String sch6 = '0 50 * * * ?';
String jobId = System.schedule('(Every 50min)', sch6, new myScheduleClass());
Thanks,
Krishna
Below code can fulfill your requirements. Hope this will work for you.
global class ScheduleEveryMinutes implements Schedulable {
global void execute(SchedulableContext SC) {
AccountCountBatch countacc = new AccountCountBatch();
Database.executebatch(countacc);
// ScheduleEveryMinutes m = new ScheduleEveryMinutes();
//Integer sch = '0 */10 * ? * *';
// String jobID = system.schedule('Every 10 Minutes', sch, m);
// AccountCountBatch.startJob();
String day = string.valueOf(system.now().day());
String month = string.valueOf(system.now().month());
String hour = string.valueOf(system.now().hour());
String minute = string.valueOf(system.now().minute() + 10);
String second = string.valueOf(system.now().second());
String year = string.valueOf(system.now().year());
String strJobName = 'Job-' + second + '_' + minute + '_' + hour + '_' + day + '_' + month + '_' + year;
String strSchedule = '0 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
System.schedule(strJobName, strSchedule, new ScheduleEveryMinutes());
}
}
Please mark this as best answer if this solves your problem.
Thank you
Ajay Dubedi
Howto execute this above code.