Is there a way to schedule an apex class(schedulable of course) to run every second week?

I thought I could do it in the UI by scheduling 2 jobs for 2nd and 4rd Friday of the month, but the moment I try to schedule the second one I get the error:

Error: This Apex class is already scheduled for execution.

I have seen this answer, but that doesn't really fit my needs. My batch should only start executing every second Friday after work hours.

I was also thinking about using cron, but couldn't find a way to schedule it for every second and fourth Friday of the month.

  • what about this cron: 0 1 8-14,21-28 * 5
    – kurunve
    Nov 7 '17 at 7:06

Here are the cron expressions for the schedule.

Every 2nd Friday of a Month at 8 PM

0 0 20 ? 1/1 FRI#2 *

Every 4th Friday of a Month at 8 PM

0 0 20 ? 1/1 FRI#4 *

The code to run in developer console anonymous block to schedule the jobs

System.schedule('2nd Friday Schedule', '0 0 20 ? 1/1 FRI#2 *', new YourApexClass());
System.schedule('4th Friday Schedule', '0 0 20 ? 1/1 FRI#4 *', new YourApexClass());

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.