Loading

Purge AsyncApexJob to delete already executed asynchronous Apex job records

게시 일자: Jun 9, 2026
상세 설명

Queries against AsyncApexJob may receive this message:
System.QueryException: Non-selective query against large object type (more than 100,000 rows). Consider an indexed filter or contact Salesforce about custom indexing.
When the number of AsyncApexJob records exceeds 100,000, SOQL queries against this object throw a non-selective query error. Salesforce automatically purges completed AsyncApexJob records after 7 days, but in high-volume orgs this automatic cleanup may not be sufficient to keep the record count below the 100,000 threshold.

솔루션

Default Behavior: Automatic Purge After 7 Days

Salesforce automatically purges completed AsyncApexJob records 7 days after execution. In most orgs, this is sufficient to prevent record buildup. However, in orgs with a high volume of scheduled or batch Apex jobs, records may accumulate faster than the automatic purge can clear them.

How to Manually Purge AsyncApexJob Records (API v65 and Earlier)

Use the purgeOldAsyncJobs(Date) method to delete all completed async jobs with a CreatedDate before the specified date. Call this method from Execute Anonymous Apex in the Developer Console or from a scheduled Apex class.

How to Purge with an Upper Bound (API v66 and Later)

In API version 66.0 and later, use the method overload purgeOldAsyncJobs(Date, numOfJobs) to specify the maximum number of oldest completed async jobs to purge in a single operation. Providing an upper bound allows incremental deletion when you need to remove large volumes without hitting Apex governor limits in a single transaction.
추가 자원
Knowledge 기사 번호

000383655

 
로드 중
Salesforce Help | Article