[SalesForce] Schedule a apex batch class to run every 5 min

I have an apex batch class that does not implement Scheduleable Interface. I wish to schdule this batch job to run every 5 minutes of an hour all week. Is it
possible to do without implementing the schedulable interface? If so how?

What I know:

I saw there is a method to schedule the apex batch class using – System.scheduleBatch , but this schedules the job to run only once and not every 5 minutes of a hour.

Using the System.scheduleBatch Method You can use the
System.scheduleBatch method to schedule a batch job to run once at a
future time.

The System.scheduleBatch method takes the following parameters. An
instance of a class that implements the Database.Batchable interface.
The job name. The time interval, in minutes, after which the job
starts executing.

Best Answer

You can run a batch with five minutes between each execution using system.scheduleBatch by chaining it in your finish method. It won't run every five minutes, because it also takes some time to execute.

You'll want to add some sort of kill switch so your batch is possible to test.

@TestVisible static Boolean chainBatches = true;
public void finish(Database.BatchableContext context)
{
    String jobName = 'MyJob' + Datetime.now();
    if (chainBatches) system.scheduleBatch(this, jobName, 5);
}
Related Topic