Print this page

Run a scheduled Apex job once

Knowledge Article Number 000002809

Using Scheduled Apex UI you can not set a scheduled class to run only once, it's always recurring. So, you'll need to use System.scheduled via the system log to implement a workaround


Example code for running a job 10 minutes from now only once


String hour = String.valueOf(;
String min = String.valueOf( + 10); String ss = String.valueOf(;

//parse to cron expression
String nextFireTime = ss + ' ' + min + ' ' + hour + ' * * ?';

MyScheduledJob s = new MyScheduledJob(); System.schedule('Job Started At ' + String.valueOf(, nextFireTime, s);

Abort the job by adding a finish method to your class that implements the Schedulable Interface. This stops the job from running more than once.


Example code to abort the job

global void finish(Database.BatchableContext BC)
// Get the ID of the AsyncApexJob representing this batch job from Database.BatchableContext.
// Query the AsyncApexJob object to retrieve the current job's information.
AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email ..... FROM AsyncApexJob WHERE Id = 

//then use the active job id and abort it

promote demote