0

I have come across a strange case where the same batch job was running with two different users and went in to dig upon and found that one was scheduled via Schedule Apex screen and another one using Cron statement.

Either the case SalesForce should not let one to create a second/duplicate batch job if there is already one scheduled right on the same Apex Class?

  • 5
    Why would you think this behavior is not supposed to be allowed? – Adrian Larson Dec 28 '16 at 16:08
  • If you try scheduling the same job from UI, it would throw an error complaining about being duplicate. That is why my whole point started does or should SalesForce has a right mechanism to find duplicates and complain about them. It is a waste of processing time and records will be locked anyways by doing so. – DJD Dec 28 '16 at 16:16
1

You can schedule the same job as many times as you wish. Take a look through the Apex Developer Guide page on Apex Scheduler, there is no mention anywhere on the page that you can only schedule a give class once. In fact, it is quite common to schedule a specific Apex Class multiple times, and you can do so via the System.schedule method or through the UI, or a combination thereof.

As long as you don't go over 100 scheduled jobs, this is expected behavior. We even have some very popular answers that recommend scheduling the same class multiple times, for example: How to run a scheduled job every 15 minutes?

  • If you try scheduling the same job from UI, it would throw an error complaining about being duplicate. That is why my whole point started does or should SalesForce has a right mechanism to find duplicates and complain about them. It is a waste of processing time and records will be locked anyways by doing so. – DJD Dec 28 '16 at 16:16
  • In your particular case, it may be a waste of resource, but often it is not. This behavior is WAD. – Adrian Larson Dec 28 '16 at 16:19
  • And Adrian, agree on you can schedule as many jobs as we want dah! But my point is should it allow duplicates to run at the same time for example batch1 to run at 6AM for a given apex class and batch2 to run at same 6AM for same given apex class. Then definitely we will end up with row locks and it is a waste of resources. – DJD Dec 28 '16 at 16:19
  • 1
    Only someone with the Author Apex permission can schedule a job, generally. These users should be trusted to do the right thing. If someone is scheduling jobs via the System.schedule method when they should not, you have a people problem, not a platform problem. – Adrian Larson Dec 28 '16 at 16:22
0

I had similar case where production had 7 scheduled jobs for the same class with different intervals (may be different scenarios,some of them were dups as well).

I would say its a miss management if one does schedule same class at the same time if it is already scheduled at that time.

Better to run anonymous snippet to abort existing jobs (both manual & cronTriggers) & then schedule it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.