Job.apex

  • Docs
  • Tutorials
Docs Menu
  • Job
  • Job Methods
    • Constructors
    • Common Methods
    • Cron Expression Job Methods
    • Repeating Job Methods
  • Jobs Methods

Job Guide

Job

Jobs

We have two types of Jobs here.

The first type is cron expression jobs, which builds cron expressions internally and delegate everything to cron expression scheduling.

The other type is repeating jobs, which repeat themselves at a given interval, and are more flexible in use.

Repeating jobs are defined by using methods like 'startAt(Xxx)' or 'startNow()', followed by 'afterXxx' and 'repeatXxx'.

Dependencies

Job.apex has a dependency over R.apex. We utilize R.apex to grant the power of functions to Job.apex.

Job Executor

We separate the job execution from job scheduling. So users only need to pass in job executors, and Job.apex will take care of the job scheduling.

public class CustomJob extends Func {
    public CustomJob() {
        super(1);
    }

    public override Object exec(Object context) {
        System.debug('Custom job executed');
        return null;
    }
}

Here we defined a CustomJob executor with our custom logic inside it. Then we can schedule our job like this:

new Job('test', new CustomJob()).everyDay().atHour(8).schedule();

Contribute on Github! Edit this section.