|Knowledge Article Number||000193840|
|Description||Queries against AsyncApexJob may receive this message:
System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce about custom indexing.
Completed AsyncApexJob records are automatically purge by salesforce after 7 days. If the number of records grows above 100,000 customers should consider implementing this (from apex docs):
Deletes asynchronous Apex job records for jobs that have finished execution before the specified date with a Completed, Aborted, or Failed status, and returns the number of records deleted.
public static Integer purgeOldAsyncJobs(Date dt)
Asynchronous Apex job records are records in AsyncApexJob.
The system cleans up asynchronous job records for jobs that have finished execution and are older than seven days. You can use this method to further reduce the size of AsyncApexJob by cleaning up more records.
Each execution of this method counts as a single row against the governor limit for DML statements.
This example shows how to delete all job records for jobs that have finished before today’s date.
Integer count = System.purgeOldAsyncJobs (Date.today()); System.debug('Deleted ' + count + ' old jobs.');