Keep Up with the Latest Salesforce CLI Enhancements

Stay up to date with recent Salesforce CLI enhancements.

Where: These changes apply to Salesforce CLI version 2.104.6 and later.

How: Read the Salesforce CLI weekly release notes for detailed information about all the new and changed features and issue fixes in recent releases.

Improve Deploy Performance by Running Only Relevant Apex Tests

Run only relevant Apex tests when you deploy metadata to your org. Use the new RunRelevantTests value of the --test-level flag of the project deploy start|validate commands. You can also use the same flag with the project delete source command.

Salesforce automatically identifies the relevant tests based on an analysis of the deployment payload and the payload dependencies.

This example deploys source files in the force-app package directory to the org with the alias my-scratch and runs only relevant Apex tests:

sf project deploy start --source-dir force-app --test-level RunRelevantTests --target-org my-scratch

Run Apex and Flow Tests with a Single CLI Command (Beta)

Note
Note This feature is a beta service that is subject to the Beta Services Terms at Agreements - Salesforce.com or a written Unified Pilot Agreement if executed by Customer, and applicable terms in the Product Terms Directory. Use of this pilot or beta service is at the Customer's sole discretion.

Ensure interoperability between Apex classes and flows by running their tests in a single and unified way with these new CLI commands:

  • logic run test: Run tests for Apex and Flows in an org.
  • logic get test: Get the results of an async test run, or if it timed out.

Many flags of these new commands mimic the flags for the existing apex run|get test and flow run|get test commands, such as --tests, --test-level, --code-coverage, --class-names, and --output-dir. But the new logic run test command expands the --tests flag so that you can specify both Apex and flow tests and adds a --test-category flag to narrow the type of tests you want to run.

By default, the logic run test command runs asynchronously and returns a test run ID. Then use the logic get test command to retrieve the results.

This example runs all local Apex and flow tests in the org with the alias my-scratch asynchronously:

sf logic run test --test-level RunLocalTests --test-category Apex --test-category Flow --target-org my-scratch

The command returns a test run ID that you pass to the logic get test command to get the test results:

sf logic get test --test-run-id <test-run-id>

Retrieve Package Metadata for a Specified Package Version

You can retrieve package metadata for only second-generation managed package versions or unlocked packages.

This example shows how to retrieve package metadata for a converted subscriber package version ID (starts with 04t) into my-directory in your Salesforce DX project directory:

sf package version retrieve --package 04tXXX --output-dir my-directory --target-dev-hub devhub@example.com

Customize the Timeout When Attempting to Log Into an Org

If you try to authorize an org with the org login web CLI command, and it runs into an issue, the CLI command now times out after 2 minutes, rather than hanging indefinitely. Customize the number of milliseconds that the command waits to time out with the new SF_WEB_OAUTH_SERVER_TIMEOUT environment variable. The default value is 120000 (2 minutes).

This example sets the timeout to 3 minutes:

export SF_WEB_OAUTH_SERVER_TIMEOUT=180000

Customize the Apex Test Polling Interval

Specify the number of seconds to poll the org to check for the test status when you run apex test run with the new --poll-interval flag. Previously the poll interval was hard-coded to 1 second. This example shows how to set the poll interval to 5 seconds:

sf apex run test --class-names MyClassTest --result-format human --poll-interval 5 --target-org my-org