Skip to main content Join us at TDX in San Francisco or on Salesforce+ on March 5-6 for the Developer Conference for the AI Agent Era. Register now.

Hi,  

 

I have written a apex class , in which I need to schedule that class every 5 minute.  

I tried executing below Approaches : 

 

Option 2: This executing every 5 mins per hour

global with sharing class ScheduleBatchApexDemo implements Schedulable {global void execute(SchedulableContext sc) { PricingEventReviewAggregatorContract.createPricingLogItemsContract();}Public static void SchedulerMethod() { string timeinterval = '0 5 * * * ?'; System.schedule('ScheduledDemo-Every5mins',timeinterval, new ScheduleBatchApexDemo()); }}

Please help if there is any optimized approach 

@* Salesforce Developers *

Option 1 : Executed code in anonymous window. But I dont want to have n number of scheduled Jobs. System.schedule('Schedule Job Name 1',  '0 00 * * * ?', new ScheduleBatchApexClassExample());System.schedule('Schedule Job Name 2',  '0 05 * * * ?', new ScheduleBatchApexClassExample());System.schedule('Schedule Job Name 3',  '0 10 * * * ?', new ScheduleBatchApexClassExample());System.schedule('Schedule Job Name 4',  '0 15 * * * ?', new ScheduleBatchApexClassExample());System.schedule('Schedule Job Name 5',  '0 20 * * * ?', new ScheduleBatchApexClassExample());System.schedule('Schedule Job Name 6',  '0 25 * * * ?', new ScheduleBatchApexClassExample());System.schedule('Schedule Job Name 7',  '0 30 * * * ?', new ScheduleBatchApexClassExample());System.schedule('Schedule Job Name 8',  '0 35 * * * ?', new ScheduleBatchApexClassExample());System.schedule('Schedule Job Name 9',  '0 40 * * * ?', new ScheduleBatchApexClassExample());System.schedule('Schedule Job Name 10', '0 45 * * * ?', new ScheduleBatchApexClassExample());System.schedule('Schedule Job Name 11', '0 50 * * * ?', new ScheduleBatchApexClassExample());System.schedule('Schedule Job Name 12', '0 55 * * * ?', new ScheduleBatchApexClassExample());
4 answers
  1. Feb 28, 5:59 PM

    I would consider a Queueable with a delay interval of 5 minutes that perpetually re-enqueues itself. 

     

    "Adding a Queueable Job with a Specified Minimum Delay" 

    https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_queueing_jobs.htm

     

     

    If your jobs runs long, you may want to enqueue it for 4 minutes instead of 5.  

     

    Queueables aren't guaranteed to be able to reenqueue so I might back it up with a finalizer to start a new chain, log errors, etc... and also possible a single hourly scheduled job to check the enqueued job and make sure your job is running successfully and restart it if needed.

  2. Yesterday, 11:19 AM

    Try scheduling the apex class 5 minutes from the time it finishes every time it finishes. You will only have a schedule (5 minutes from now) for this class.

  3. Yesterday, 11:08 AM

    Hello @Sanjana Rajasekar

    By default, you can run an apex job every 1 hour using cron expression but you can schedule this job 12 times at 5 min duration. However, only 100 Apex classes can be scheduled concurrently and 5 batch Apex jobs can be queued or active concurrently. 

    Refer to this:

0/9000