3

I am working on a scheduler class. I want to schedule my job after every 5 minutes. But i am not getting the correct CRON expression for that. Can anyone please guide me on this. Also let me know how to for a CRON Expression?

Pankaj
  • 2,525
  • 2
  • 41
  • 70
  • Just so that you're aware, your scheduled Apex jobs now count against the Asynchronous Apex limit for your org as discussed here in this blog: http://blogs.developerforce.com/engineering/2013/06/consolidating-apex-limits.html

    I'm not sure what your goal is to run a job every 5 minutes, but just want to make sure you're mindful of the impact on other Apex resources (batch and future calls)

    – pchittum Jul 06 '13 at 00:09

3 Answers3

13

As Doug says, this is not apparently possible in Salesforce Cron trigger. You may want to consider a 'self re-scheduling' job, e.g.

    global class SelfSchedule implements schedulable
    {    
        global void execute( SchedulableContext SC )
        {        

           // do whatever it is you want to do here

            SelfSchedule.start();

            // abort me and start again
            System.abortJob( SC.getTriggerId() );
        }

        public static void start()
        {
            // start keepalive again in 5 mins
            Datetime sysTime = System.now().addSeconds( 300 );      
            String chronExpression = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' + sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
            System.schedule( 'SelfSchedule ' + sysTime, chronExpression, new SelfSchedule() );
        }

    }

You may also want to consider the solution I outlined here.

Note the issues pointed out in the OP though, every 5 minutes might on occasions be problematic.

Phil Hawthorn
  • 16,718
  • 3
  • 46
  • 74
1

Regular Cron would allow this, but in Salesforce Cron trigger it is not possible to schedule every 5 minutes. You must specify actual values for minutes / seconds.

You can schedule it every X hours, but not every X minutes.

Doug B
  • 11,442
  • 1
  • 36
  • 43
0

As an option: make 12 identical entry's at 0, 5, 10 , 15 .. minutes. Works, but "self re-scheduling" is much better.

WvB
  • 63
  • 5