
We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.
If an Apex test class is stuck in the Salesforce job execution queue and you receive the error:Unable to invoke async test job: This test is already in the execution queue.
You need to abort the queued ApexTestQueueItem records before you can re-run the test.
ApexTestQueueItem is the Salesforce object that represents Apex test jobs in the asynchronous job queue. When tests are queued but not yet completed, their status can be set to "Aborted" to cancel execution. You can do this by running an Anonymous Apex script in the Developer Console.
Per the Salesforce documentation: "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."
Run the following Apex code as Anonymous Apex in the Developer Console (Help > Developer Console > Debug > Open Execute Anonymous Window):
List<ApexTestQueueItem> items = [Select Id,ApexClassId,Status,ExtendedStatus,ParentJobId from ApexTestQueueItem where Status != 'Completed'];
for(ApexTestQueueItem atqi : items) {
atqi.Status = 'ABORTED';
}
update items;
This code does the following:
After running this code, navigate to Setup > Apex Jobs and refresh the page to confirm the ApexTestQueueItem records have been aborted. You can then re-run your test classes without encountering the "already in the execution queue" error.
This script aborts all non-completed queued test items in the org. If you only want to abort specific tests, add a filter to the SOQL query, for example by specifying the ApexClassId of the test class you want to abort.
000384395