Loading

Abort Apex test class execution using ApexTestQueueItems

Дата публикации: Oct 13, 2022
Описание
"To abort a class that is in the Apex job queue, perform an update operation on the ApexTestQueueItem object and set its Status field to Aborted."

If you get the following error:
Unable to invoke async test job: This test is already in the execution queue.

You'll need to perform the below actions. 

In order to do this you can set the ApexTestQueueItems to aborted with the following Apex Code which you can run in Anonymous Apex:
Решение
List<ApexTestQueueItem> items = [Select Id,ApexClassId,Status,ExtendedStatus,ParentJobId from ApexTestQueueItem where Status != 'Completed'];
for(ApexTestQueueItem atqi : items) {
    atqi.Status = 'ABORTED';
}
update items;

This will allow you to successfully abort the ApexTestQueueItems.
Номер статьи базы знаний

000384395

 
Загрузка
Salesforce Help | Article