The independent daily for Salesforce admins, developers and architects

Curated by Abhinav (opens in a new tab)

Must-read

When Salesforce runs Apex tests on a deployment, and how to run fewer (opens in a new tab)

You will learn which test levels Salesforce applies by default, the coverage rules that constrain RunSpecifiedTests, and five practical ways to shorten production deployments.

Why read this

The post also flags that one Flow-related default is not yet verified in production.

  1. Check whether the package contains Apex or Flows
  2. Pick a test level or accept the default
  3. Apply the 75% coverage rule
  4. Quick deploy a validated package
How Salesforce decides which Apex tests to run on a production deployment

Apex tests are usually the slowest part of a Salesforce deployment to production. The article lists the test levels the Salesforce CLI offers: NoTestRun, RunSpecifiedTests, RunLocalTests, RunAllTestsInOrg and RunRelevantTests, the last still in beta. When no level is chosen, the default depends on the target: sandboxes and Developer Edition orgs run no tests, while production runs all local tests if the package contains Apex classes or triggers. The author notes that Flows set to activate on deployment also count, which is a common cause of unexpectedly slow deployments.

The coverage rules decide whether a production deployment can pass. With RunLocalTests or RunAllTestsInOrg, the org needs at least 75% Apex coverage overall and every test that runs must pass. With RunSpecifiedTests, each Apex class and trigger in the package needs 75% coverage on its own from the named tests, so a class with no selected test fails even when a full run would have passed.

The article gives five ways to run fewer tests: keep unchanged Apex out of the package, deploy only the differences from the target, specify tests while checking per-class coverage, consider RunRelevantTests with its beta limits in mind, and validate ahead then quick deploy within 10 days. It also suggests shipping configuration separately from code, since a package with no Apex needs no tests at the default level. The author tested check-only deployments against a Developer Edition org only, so the Flow default has not been confirmed in production. The post closes by describing how the Diffbridge tool’s Smart test level automates these choices.

Read the original at dev.to (opens in a new tab)

Worth reading?