I want to run an apex code every 30 seconds and want to use Scheduled Jobs. However, there are limitations on it. So far I have read the following options: 1- Run it on another server (e.g., unix) 2- Use multiple Scheduled jobs that run independently with specific intervals 3- Chain scheduled jobs by creating a new one after the old one is done.

All of these seem to work but are workarounds. Some of them seem to be old too. What's the best way to do this? Is there a better way?

  • 1
    In Salesforce you can never be sure that a job starts exactly at the time you scheduled it. This can be even minutes off. That is related to the multitenant infrastructure of the system. Server loads are spread in time. So if you want to do something exactly every 30 secs, option 1 is your only option. Commented Oct 2, 2014 at 20:01
  • In addition to @guy's comment. If a Scheduled Job is during a SalesForce maintenance window and SF have brought down that server, the Scheduled Job will not run until the server is brought back up
    – BarCotter
    Commented Oct 3, 2014 at 8:52

1 Answer 1


you can do it like below :

Datetime sysTime = System.now().addSeconds( 30 );
String chronExpression = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' + sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();

System.schedule( 'scheduledBatchable ' + sysTime, chronExpression, new scheduledBatchable() );

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .