How to Schedule Apex to run every 2, 5, 10 minutes in Salesforce

Hello Folks, In this post, I’m going to show you how you can schedule an apex class every 2  minutes or whatever interval you want to set in minutes using the CRON expression.

Schedule Apex every 2 or n minutes in Salesforce

In Salesforce Apex, Scheduling a class every 2 minutes or n minutes is not possible by the standard Salesforce user interface, But you can achieve this by following the below code.

As you are going to schedule an Apex Class so make sure your class implements the schedulable Interface.

In this example, I’m scheduling this apex class from the finish method of a batch you can use the scheduling logic as per your logic or scenario.

by doing this you will get a recurring schedule class that executes your logic every n minutes of your choice.

Spread the love

Related Posts

One thought on “How to Schedule Apex to run every 2, 5, 10 minutes in Salesforce

  1. Hi.
    There are 2 issues:
    1.Few syntax error in the code snippet that prevent it from compiling (line 22 – no such contractor, 23- missing CONSTANT)
    2.As it is not setting any expression for the day, then by default it will be daily, therefore in the finish before scheduling the next run you need to abort the previous job. Otherwise after 100 cycle you will have 100 jobs in the scheduled jobs and it will hit the limit.

    I’m using app tool for managing the jobs and recently publish it:

Leave a Reply

Your email address will not be published. Required fields are marked *