ApexTestResult

Represents the result of an Apex test method execution.

Version 

Introduced in API version 23.0.

Supported SOAP API Calls 

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

Supported REST API Methods 

DELETE, GET, HEAD, PATCH, POST, Query

Fields 

ApexClassId 

  • Type: reference

  • Required: No

  • Properties: Create, Filter, Group, Nillable, Sort, Update

  • Description: The Apex class whose test methods were executed.

  • Relationship name: ApexClass

  • Relationship type: relationship

  • Refers to: ApexClass

ApexLogId 

  • Type: reference

  • Required: No

  • Properties: Create, Filter, Group, Nillable, Sort, Update

  • Description: Points to the ApexLog for this test method execution if debug logging is enabled; otherwise, null.

  • Relationship name: ApexLog

  • Relationship type: relationship

  • Refers to: ApexLog

ApexTestRunResultId 

  • Type: reference

  • Required: No

  • Properties: Create, Filter, Group, Nillable, Sort, Update

  • Introduced: API version 37.0

  • Description: The ID of the ApexTestRunResult that represents the entire test run.

  • Relationship name: ApexTestRunResult

  • Relationship type: relationship

  • Refers to: ApexTestRunResult

AsyncApexJobId 

  • Type: reference

  • Required: No

  • Properties: Create, Filter, Group, Nillable, Sort, Update

  • Description: Points to the AsyncApexJob that represents the entire test run.

This field points to the same object as ApexTestQueueItem.ParentJobId.

  • Relationship name: AsyncApexJob
  • Relationship type: relationship
  • Refers to: AsyncApexJob

IsTestSetup 

  • Type: boolean

  • Required: No

  • Properties: Create, Defaulted on create, Filter, Group, Sort, Update

  • Introduced: API version 61.0

  • Description: Indicates if the results are for a test setup method. The default is false.

  • Default value: false

Message 

  • Type: string

  • Required: No

  • Properties: Create, Filter, Nillable, Sort, Update

  • Description: The exception error message if a test failure occurs; otherwise, null.

MethodName 

  • Type: string

  • Required: No

  • Properties: Create, Filter, Group, Nillable, Sort, Update

  • Description: The name of the test method.

Outcome 

  • Type: picklist

  • Required: No

  • Properties: Create, Filter, Group, Restricted picklist, Sort, Update

  • Description: The result of the test.

  • Possible values:

    • Pass — Pass

    • Fail — Fail

    • CompileFail — CompileFail

    • Skip — Skip

QueueItemId 

  • Type: reference

  • Required: No

  • Properties: Create, Filter, Group, Nillable, Sort, Update

  • Description: Points to the ApexTestQueueItem which is the class that this test method is part of.

  • Relationship name: QueueItem

  • Relationship type: relationship

  • Refers to: ApexTestQueueItem

RunTime 

  • Type: int

  • Required: No

  • Properties: Create, Filter, Group, Nillable, Sort, Update

  • Introduced: API version 37.0

  • Description: The time it took the test method to run, in seconds.

StackTrace 

  • Type: string

  • Required: No

  • Properties: Create, Filter, Nillable, Sort, Update

  • Description: The Apex stack trace if the test failed; otherwise, null.

TestCategory 

  • Type: string

  • Required: No

  • Properties: Filter, Group, Nillable, Sort

  • Introduced: API version 67.0

  • Description: The category of the test class.

Possible values are:

TestName 

  • Type: string

  • Required: No

  • Properties: Create, Filter, Group, Nillable, Sort, Update

  • Introduced: API version 65.0

  • Description: The name of the test class.

TestNamespace 

  • Type: string

  • Required: No

  • Properties: Create, Filter, Group, Nillable, Sort, Update

  • Introduced: API version 65.0

  • Description: The namespace of the test class.

Apex tests are in the default namespace, so theTestNamespace value for Apex tests is null.

Flow tests are in the FlowTesting namespace. If a flow test is in a namespaced package or org, the TestNamespace value is FlowTesting.<NamepacePrefix>.

TestTimestamp 

  • Type: datetime

  • Required: No

  • Properties: Create, Filter, Sort, Update

  • Description: The start time of the test method.

Usage 

You can query the fields of the ApexTestResult record that corresponds to a test method executed as part of an Apex class execution.

Each ApexTestResult record represents a single test method execution. For example, if an Apex test class contains six test methods, six ApexTestResult records are created. These records are in addition to the ApexTestQueueItem record that represents the Apex class.

Each ApexTestResult record has an associated ApexTestResultLimits record, which captures the Apex limits used during execution of the test method.

For example code, see ApexTestQueueItem.

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!