Newer Version Available

This content describes an older version of this product. View Latest

ApexTestQueueItem

Represents a single Apex class in the Apex job queue. Available in API version 30.0 and later.

Supported SOAP API Calls

create()describeSObjects()query()retrieve()update()upsert()

Supported REST API HTTP Methods

Query, GET, POST, PATCH

Fields

Field Name Details
ApexClassId
Type
reference
Properties
Create, Filter, Group, Sort
Description

The Apex class whose tests are to be executed.

This field can't be updated.

Status
Type
picklist
Properties
Filter, Group, Restricted picklist, Sort, Update
Description
The status of the test. Valid values are:
  • Queued
  • Processing
  • Aborted
  • Completed
  • Failed
  • Preparing
  • Holding

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.

ExtendedStatus
Type
string
Properties
Filter, Nillable, Sort
Description

The pass rate of the test run.

For example: “(4/6)”. This means that four out of a total of six tests passed.

If the class fails to execute, this field contains the cause of the failure.

ParentJobId
Type
reference
Properties
Filter, Group, Nillable, Sort
Description

Read-only. Points to the AsyncApexJob that represents the entire test run.

If you insert multiple Apex test queue items in a single bulk operation, the queue items will share the same parent job. This means that a test run can consist of the execution of the tests of several classes if all the test queue items are inserted in the same bulk operation.
ShouldSkipCodeCoverage
Type
boolean
Properties
Create, Defaulted on create, Filter, Group, Sort, Update
Description

Indicates whether to opt out of collecting code coverage information during Apex test runs. Available in API version 43.0 and later.

TestRunResultID
Type
reference
Properties
Filter, Group, Nillable, Sort
Description

The ID of the associated ApexTestRunResult object. Available in API version 37.0 and later.

Usage

Insert an ApexTestQueueItem object to place its corresponding Apex class in the Apex job queue for execution. The Apex job executes the test methods in the class.

The example RunTestListener.java class below subscribes to the TestResult system topic and prints out the test results using ApexTestQueueItem and ApexTestResult. The example assumes the following:
  • You have already set up a Java client application for Streaming API. This example uses the org.cometd.client.BayeuxClient created in the Java Client code example in the Streaming API Developer Guide.
  • You have a logged in com.sforce.soap.tooling.SoapConnection. For examples, see the SOAP API Developer Guide.
The RunTestListener.java class must be instantiated after the Streaming API handshake. For example:

Note