Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

Retrieve Compilation Results for Invalid Apex with the apexCompileResults Resource

Retrieve compilation results for Apex classes and triggers with validation errors. Routinely monitoring results allows you to detect and respond to compilation issues.Available in API version 68.0 and later. This resource requires the Author Apex org permission.

Syntax

  • URI: /services/data/vXX.X/tooling/apexCompileResults/
  • HTTPS Method: POST
  • Authentication: Authorization: Bearer token
  • Format: JSON

Request Parameters

None.

Request Body

The request body must be an empty JSON object ({}). Specifying any fields returns an error.

Response Body Properties

Name Type Description
status String

The operation-level outcome of the compilation.

Possible values are:

  • OK—all invalid Apex classes and triggers compiled successfully, or no invalid classes or triggers required recompilation.
  • PARTIAL_FAILURE—at least one invalid Apex class or trigger failed to compile.
results Object[]

An array of compilation outcomes for Apex classes and triggers that failed to compile.

Each object includes the class or trigger name, namespace, success indicator, errors, and warnings. Classes and triggers that compile successfully aren’t included. Warnings are included only when the class or trigger also has compilation errors.

If the entire compilation succeeds without any failures, this array is empty.

Each object in the results array can include these properties.

Name Type Description
name String The developer name of the Apex class or trigger.
namespace String The namespace of the Apex class or trigger. For the default namespace, the value is an empty string.
success Boolean Indicates whether the Apex class or trigger compiled successfully. The value is true when there are no compilation problems. The value is false when at least one problem is present. Warning-only outcomes are still considered successful, so these outcomes aren’t returned in the results array.
problems Object[] An array of compilation errors for the Apex class or trigger. Empty when success is true.
warnings Object[] An array of compilation warnings for the Apex class or trigger. Warnings are returned only for classes and triggers that also have compilation errors.

Each object in a problems or warnings array can include these properties.

Name Type Description
line Integer The source line of the error or warning. The value is 0 if a line isn’t applicable.
column Integer The source column of the problem or warning. The value is 0 if a column isn’t applicable.
message String A description of the compilation error or warning.

Usage

  • Use theapexCompileResults resource to retrieve compilation results for invalid Apex class and triggers. To recompile invalid classes or triggers, use the “Compile only invalid classes” and “Compile only invalid triggers” buttons on the Apex Classes or Apex Triggers pages in Setup. Successful compilation via the Setup buttons updates the IsValid field on the corresponding Apex class or trigger to true. Retrieving compilation results via apexCompileResults doesn’t update the field.
  • The request is synchronous.

Example

  • Example Request Body
    1{}
  • Example Response Body on Successful Compilation: Returned if all invalid Apex classes and triggers compiled successfully, or none required recompilation.
    1{
    2  "status": "OK",
    3  "results": []
    4}
    5
  • Example Response Body on Partial Failure: Returned if least one invalid Apex class or trigger failed to compile.
    1{
    2  "status": "PARTIAL_FAILURE",
    3  "results": [
    4    {
    5      "name": "MyInvalidClass",
    6      "namespace": "MyNamespace",
    7      "success": false,
    8      "problems": [
    9        {
    10          "line": 14,
    11          "column": 9,
    12          "message": "Variable does not exist: var1"
    13        }
    14      ],
    15      "warnings": [
    16        {
    17          "line": 0,
    18          "column": 0,
    19          "message": "Apex API version 18.0 is scheduled for retirement. Update to the latest API version to avoid compile failures."
    20        }
    21      ]
    22    }
    23  ]
    24}
    25