Loading

Abort Apex test class execution using ApexTestQueueItems

Fecha de publicación: Oct 13, 2022
Descripción
"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:
Solución
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.
Número del artículo de conocimiento

000384395

 
Cargando
Salesforce Help | Article