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
Sangeetha TSangeetha T 

URGENT !!!!! ---- CRON Expression run scheduler class in developer console runs every 30 minutes of a hour

Hi All

Please help me in defining the CRON expression for running a scheduler class for every 30th min of an hour 
For example first run should be 9 30 next should be 10 30 next should be 11 30 

 
Jawaad ShahJawaad Shah
Hi Sangeetha

Can you try this: 

0 30 * * * ?

Regards, Jawaad
Sangeetha TSangeetha T
Thanks Jawaad... But this will run for every half an hour it will run like 9 30 / 10 / 10 30 / 11 

But it want this to run like 9 30 / 10 30 / 11 30 ---- 30th mins post every hour not all 30 mins of hour 
Jawaad ShahJawaad Shah
Cron schedule
Hi Sangeetha

Using http://www.cronmaker.com I have entered the expression and clicked the calculate next dates button and get the outputs above for every half past the hour. 

Regards, Jawaad
Abers55Abers55
This code reschedules the job for an interval that you set each time it runs.  If you schedule the original job to run at xx:00 or xx:30 with a 30 minute interval,  you'll get the required result.  However,  since jobs only run at approximately the time you request,  this will gradually become more inaccurate.
public class ProcessingJob implements Schedulable {

	private static final string JOB_NAME = 'Your Job Name Here';

	public void execute(SchedulableContext sc) {

		//Do some processing work here....


		rescheduleJob();
	}	

	private void rescheduleJob() {

		deleteJob();

		datetime nextTime = datetime.now().addMinutes(repeatInterval);

		integer hour = nextTime.hour();
		integer minute = nextTime.minute();

		string cronTrigger = '0 ' + minute + ' ' + hour + ' * * ?';

		scheduleJob(cronTrigger);
	}

	private void deleteJob(){
		
		CronTrigger[] abortJob = [select Id from CronTrigger where CronJobDetail.Name  = :JOB_NAME];

		if(!abortJob.isEmpty()) {
			system.abortJob(abortJob[0].Id);
		}

	}

	//Use this to kick start the process with anonymous apex
	public static void scheduleJob(){

		datetime nextTime = datetime.now().addMinutes(1);

		integer hour = nextTime.hour();
		integer minute = nextTime.minute();

		string cronTrigger = '0 ' + minute + ' ' + hour + ' * * ?';

        scheduleJob(cronTrigger);
	}

	public static void scheduleJob(string cronTrigger){

        system.schedule(JOB_NAME, cronTrigger, new ProcessingJob());
	}
}
There is also a System.scheduleBatch(batchable, jobName, minutesFromNow) method that may help you out,  I think that it will probably suffer from the same problem.