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?

1
  • 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: blogs.developerforce.com/engineering/2013/06/… 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
    Commented Jul 6, 2013 at 0:09

3 Answers 3

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.

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.

0

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

You must log in to answer this question.

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