# Apex Tests

Run and analyze Apex tests in a package or org

* [`sfp apextests resume`](#sfp-apextests-resume)
* [`sfp apextests trigger`](#sfp-apextests-trigger)

## `sfp apextests resume`

Resume monitoring or fetch results for a previously triggered Apex test run. Use with --status-only to check current status without waiting, or without to wait for completion and fetch results.

```
USAGE
  $ sfp apextests resume -o <value> --testrunid <value> [--json] [--loglevel
    trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL] [--apiversion <value>] [--status-only] [-w
    <value>] [--outputdir <value>] [--outputformat raw|dashboard|both] [--environment <value>] [-c]
    [--validatepackagecoverage] [-p <value>]

FLAGS
  -c, --validateindividualclasscoverage  Validate that individual classes have a coverage greater than the minimum
                                         required percentage coverage
  -o, --targetusername=<value>           (required) Username or alias of the target org.
  -p, --coveragepercent=<value>          [default: 75] Minimum required percentage coverage, when validating code
                                         coverage
  -w, --waittime=<value>                 Wait time in minutes for test to complete. Use 0 or omit for indefinite wait
      --apiversion=<value>               Override the api version used for api requests made by this command
      --environment=<value>              Environment name for dashboard format (defaults to target org alias)
      --loglevel=<option>                [default: info] logging level for this command invocation
                                         <options: trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL>
      --outputdir=<value>                [default: .testresults] Directory to write test result files
      --outputformat=<option>            [default: raw] Output format for test results
                                         <options: raw|dashboard|both>
      --status-only                      Check current status without waiting for completion
      --testrunid=<value>                (required) The test run ID to resume or monitor (obtained from 'sfp
                                         apextests:trigger --async')
      --validatepackagecoverage          Validate that the package coverage is greater than the minimum required
                                         percentage coverage

GLOBAL FLAGS
  --json  Format output as json.

DESCRIPTION
  Resume monitoring or fetch results for a previously triggered Apex test run. Use with --status-only to check current
  status without waiting, or without to wait for completion and fetch results.

EXAMPLES
  $ sfp apextests:resume -o scratchorg --testrunid 707xx0000000000

  $ sfp apextests:resume -o scratchorg --testrunid 707xx0000000000 --status-only

  $ sfp apextests:resume -o scratchorg --testrunid 707xx0000000000 -w 30 --json
```

*See code:* [*src/commands/apextests/resume.ts*](https://source.flxbl.io/flxbl/sfp-pro)

## `sfp apextests trigger`

Triggers Apex unit test in an org. Supports test level RunAllTestsInPackage, which optionally allows validation of individual class code coverage

```
USAGE
  $ sfp apextests trigger -o <value> [--json] [--loglevel
    trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL] [--apiversion <value>] [-l
    RunSpecifiedTests|RunApexTestSuite|RunLocalTests|RunAllTestsInOrg|RunAllTestsInPackage|RunAllTestsInDomain] [-n
    <value>...] [-r <value>] [-c] [--validatepackagecoverage] [--specifiedtests <value>] [--apextestsuite <value>] [-p
    <value>] [-w <value>] [--commitsha <value>] [-r <value>] [--outputformat raw|dashboard|both] [--environment <value>]
    [--async]

FLAGS
  -c, --validateindividualclasscoverage  Validate that individual classes have a coverage greater than the minimum
                                         required percentage coverage, only available when test level is
                                         RunAllTestsInPackage
  -l, --testlevel=<option>               [default: RunLocalTests] The test level of the test that need to be executed
                                         when the code is to be deployed
                                         <options: RunSpecifiedTests|RunApexTestSuite|RunLocalTests|RunAllTestsInOrg|Run
                                         AllTestsInPackage|RunAllTestsInDomain>
  -n, --package=<value>...               Name of the package to run tests. Required when test level is
                                         RunAllTestsInPackage
  -o, --targetusername=<value>           (required) Username or alias of the target org.
  -p, --coveragepercent=<value>          [default: 75] Minimum required percentage coverage, when validating code
                                         coverage
  -r, --releaseconfig=<value>            Path to the release config file(s) to test all packages within the domain
  -r, --repourl=<value>                  Custom source repository URL to use in artifact metadata, overrides origin URL
                                         defined in git config
  -w, --waittime=<value>                 Wait time in minutes for command to finish. Use 0 or omit for indefinite wait
      --apextestsuite=<value>            comma-separated list of Apex test suite names to run
      --apiversion=<value>               Override the api version used for api requests made by this command
      --async                            Trigger tests and return immediately with test run ID (for async/resume
                                         workflow)
      --commitsha=<value>                Commit SHA to use while reporting test results in markdown format
      --environment=<value>              Environment name for dashboard format (defaults to target org alias)
      --loglevel=<option>                [default: info] logging level for this command invocation
                                         <options: trace|debug|info|warn|error|fatal|TRACE|DEBUG|INFO|WARN|ERROR|FATAL>
      --outputformat=<option>            [default: raw] Output format for test results
                                         <options: raw|dashboard|both>
      --specifiedtests=<value>           comma-separated list of Apex test class names or IDs and, if applicable, test
                                         methods to run
      --validatepackagecoverage          Validate that the package coverage is greater than the minimum required
                                         percentage coverage, only available when test level is RunAllTestsInPackage

GLOBAL FLAGS
  --json  Format output as json.

DESCRIPTION
  Triggers Apex unit test in an org. Supports test level RunAllTestsInPackage, which optionally allows validation of
  individual class code coverage

EXAMPLES
  $ sfp apextests:trigger -o scratchorg -l RunLocalTests -s

  $ sfp apextests:trigger -o scratchorg -l RunAllTestsInPackage -n <mypackage> -c
```

*See code:* [*src/commands/apextests/trigger.ts*](https://source.flxbl.io/flxbl/sfp-pro)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flxbl.io/flxbl/sfp/cli-reference-v51-release-v3/utilities/apex-tests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
