function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
middha.vikram@gmail.commiddha.vikram@gmail.com 

Apex Class scheduler

Hi,

 

Is it possible to Schedule a apex class at interval of 5 minutes ? I want it to run after every 5 minutes. Is it possible in Salesforce. ?

 

Regards

Vikram

SramaKSramaK

Hi Vikram,

 

From the salesforce interface , you can only schedule an apex class once every hour.

Using apex code you can schedule 10 apex classes every hour. At most you can schedule  every 6 minutes.

You will have to schedule the same apex class 10 times every hour at 0th,6th,12th.... 54th minute.

But this way you would use all the available 10.

You can may be try every 10 minutes using 6 of the 10 if its fine.

 

If you can tell what exactly is your requirement ,there may be other ways to achieve it.

 

Regards,

Sandeep

sfdcfoxsfdcfox

You can only schedule for a specific minute/hour mark, in order to prevent exactly what you'are attempting to do. So, you'd have to schedule 12 events spread apart every five minutes. However, there is the limitation of 10 scheduled classes per organization, and you would need 12 in order to execute every five minutes. So, that means you could execute every six minutes, in theory, spacing the schedules six minutes apart. However, in practice, your scheduled class would actually run four to six times per hour, in 10 or 15 minute intervals; executions would be run back-to-back. This limitation occurs because it is not a true "cron" system like in *NIX (which literally runs once per minute). Their scheduler runs only once every 10 or 15 minutes or so, so trying to obtain granularity smaller than that would be pointless. Also, you're limited to how many scheduled events can occur per day (200), which places your minimum execution time to 18 minutes, or in practice, 20-30 minutes between each effective invocation.

 

Out of curiousity, why do you need this small of granularity in a scheduled class? There are a lot of other features available, such as Outbound Messaging, asynchronous processing (via @future methods), time-based workflow rules, and other features.

middha.vikram@gmail.commiddha.vikram@gmail.com

Hi All,

 

Thanks for your quick response. The requirement is that I need to schedule a job that will run every 5 minutes and will poll data from third party System and updates that data in Salesforce. It looks like scheduling it every 5 minutes is not a good idea. 

Can you please tell me how can I schedule it for 1 hour as I dont see this option in Salesforce UI interface. It allows only for Monthly and weekly.

 

Thanks

Vikram

SramaKSramaK
 scheduledMerge m = new scheduledMerge();
        String sch = '0 0 * * * ?';
        system.schedule('Merge Job', sch, m); 

The above code will schedule you apex class for every hour.

Where scheduledMerge is the name of the apex class.

 

Let me know if it works or if you find any issues while scheduling.

Anis_SFDCAnis_SFDC

I have a similar requirement,

 

I need to track LoginHistory to check if corporate Authentication service is down, which could be tracked based on Status field. However, I don't think we can write a trigger on LoginHistory and there is a limitation with Apex Scheduler as we can have only 10 scheduled jobs in queue.

 

Any workaround? :)