Use the new method overload for purgeOldAsyncJobs() to specify the
number of oldest, completed async jobs in your org to purge. Providing an upper bound for the
number of records to delete enables incremental progress when large volumes of records are to be
deleted.
Where: This feature is available in API version 66.0 and later. This feature is available in Lightning Experience and Salesforce Classic in Enterprise, Performance, Unlimited, and Developer editions.
How: Specify the number of completed async jobs to delete, starting from the oldest jobs that finished before the specified date. This example shows how to delete up to 1000 job records for jobs that finished before today’s date.
Integer maximumNumberOfJobsToDelete = 1000;
Integer count = System.purgeOldAsyncJobs(
Date.today(),
maximumNumberOfJobsToDelete
);
System.debug('Deleted ' + count + ' old jobs.');