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
New_DeveloperNew_Developer 

Help with Apex Scheduler

Hi,

Iam trying to schedule a apex job that runs for every 30 mins from 6PM to 11 PM. Here is the scheduler iam trying to use

ScheduledClass obj= new ScheduledClass();
String sch = '0 0,30 18,19,20,21,22,23 ? * MON-FRI';
System.schedule('My Job', sch, obj);

But iam getting the below error

System.StringException: Seconds and minutes must be specified as integers: 0 15,30,45 18,19,20,21,22,23 ? * MON-FRI

Is there any way we could scehdule a job which could run for every 30 mins starting from  6 PM and ending at 11.30 PM??

Thanks
@anilbathula@@anilbathula@
Hi New_Developer,

Try this piece of code:-

ScheduledClass obj= new ScheduledClass();
String sch = '0 30 18-23 ? * MON-FRI';
System.schedule('My Job1', sch, obj);

Thanks
Anil.B
nitesh gadkarinitesh gadkari
Hi,

ScheduledClass obj= new ScheduledClass();

String seconds = ’0′; //Execute at Zero Seconds
String minutes = ’30,60′; //Execute at every 30th minute of hour
String hours = ‘18-23’; // Execute between 6 -11 pm
String dayOfMonth = ‘*’; // Execute Every Day of the Month
String month = ’*′; //Execute every month
String dayOfWeek = ‘?’; //Execute on all 7 days of the Week
String year = ’2014′; //Execute only for year 2014

String sch = seconds + ‘ ‘ + minutes + ‘ ‘ + hours + ‘ ‘ + dayOfMonth + ‘ ‘ + month + ‘ ‘ + dayOfWeek + ‘ ‘ + year;


system.schedule(‘schedule1’, sch, obj);

Regards
Nitesh Gadkari
New_DeveloperNew_Developer
Thanks you both for replying...

@anibathula... your expression will run at 6.30 PM , 7.30 PM etc .. I want the clas to run at 6.30PM , 7.00PM , 7.30 PM etc

@nitesh .. i tried yours but it is throwing error as System.StringException: Minute and Second values must be between 0 and 59
nitesh gadkarinitesh gadkari
Hi,

try

String minutes = ’0,30′; //Execute at every 30th minute of hour
or
String minutes = ’0,30,0′; //Execute at every 30th minute of hour

New_DeveloperNew_Developer
Thanks nitesh, its still not working

its just giving me the same error message System.StringException: Seconds and minutes must be specified as integers:

i tried below two.

ScheduledClass obj= new ScheduledClass();
String sch = '0 0,30 18,19,20,21,22,23 ? * MON-FRI';
System.schedule('My Job', sch, obj);

ScheduledClass obj= new ScheduledClass();
String sch = '0 0,30 ,0 18,19,20,21,22,23 ? * MON-FRI';
System.schedule('My Job', sch, obj);