Salesforce deployment test coverage requires 75% org-wide coverage for any deploy to production that includes Apex, and every trigger needs some coverage of its own. That single sentence is where most teams stop reading the documentation, and it is also where most deployment failures start. The real rules involve class-level minimums, test isolation, and execution context, and none of those show up clearly until a deploy is already failing.

The 75% Rule Nobody Fully Understands

Salesforce will not let you deploy Apex to production unless your org-wide test coverage sits at 75% or higher. That number gets quoted constantly, but the mechanics behind it get ignored. Coverage is calculated across all Apex in the org at deploy time, not just the classes or triggers included in your change set or metadata package.

This means a deploy can fail because of untested legacy code that has nothing to do with your release. I have watched teams spend two days debugging a feature that was never broken, only to discover a five-year-old integration class was dragging the org average below threshold. The fix had nothing to do with their actual deployment.

Salesforce also requires every trigger to have at least one line of coverage, separate from the org-wide percentage. A trigger with zero tests blocks deployment even if your overall org coverage is sitting at 95%. Both conditions have to pass. Teams that only track the headline number get caught by the trigger rule constantly.

Class-Level Coverage vs Org-Wide Coverage

Org-wide coverage is a blended average, and averages hide problems. A class sitting at 0% coverage can still pass deployment if enough other classes are covered well above 75% to pull the mean up. That is legal under Salesforce's rules, but it is a bad practice that stores up risk for later.

The better standard, and the one we push teams toward with DeployEzee's pre-deploy validation, is per-class minimums. Every class touched in a given release should carry its own meaningful coverage, not just ride on the org average. A trigger handler at 20% coverage sitting next to a utility class at 98% might average out fine, but that trigger handler is the one most likely to break in production.

Here is a simple way to think about the difference:

MetricWhat Salesforce EnforcesWhat You Should Track
Org-wide coverage75% minimum to deployInformational only, not a quality signal
Trigger coverageAt least 1 line per triggerMeaningful coverage of actual logic branches
Class coverageNot individually enforced75%+ on every class touched this release

That table is the gap between passing a deploy and shipping code you actually trust. Salesforce's gate is a floor, not a quality bar.

Why Tests Pass in Sandbox and Fail in Production

A common complaint from admins is that tests run clean in a full sandbox but fail the moment the same metadata is pushed to production. The cause is almost always data dependency. Tests that query existing records, rely on specific record IDs, or assume certain configuration data exists will behave differently in an org with different data.

Production often has validation rules, required fields, or automation that the sandbox does not, especially if the sandbox has drifted since its last refresh. A test that creates an Account without a required custom field will pass in a sandbox missing that validation rule and fail in production where the rule is active. This is a data and configuration mismatch, not a coverage problem, and it gets misdiagnosed as a coverage problem constantly.

Well-written Apex tests should use @testSetup or inline Test.startTest() blocks to create their own data rather than depending on records that happen to exist in whatever org they run against. Tests that assume org state are brittle by design. If your team is debugging coverage failures that only appear in production, start by auditing whether your tests create their own data or lean on the org around them.

Flaky Tests and the Deployments They Block

Flaky tests are the quiet killer of release schedules. A test that passes 9 times out of 10 due to a timing issue, a governor limit edge case, or a SOQL query returning records in unpredictable order will eventually fail at the worst possible moment, usually during a production deployment window with stakeholders watching.

Common causes include tests that depend on System.now() without accounting for execution delay, bulk tests that assume a fixed number of DML rows when triggers fire asynchronously, and tests built against Test.isRunningTest() branches that do not mirror real execution paths. Each of these can pass in isolation and fail when run as part of a large batch, which is exactly what happens during a full deployment test run.

Running the full test suite regularly, not just at deploy time, surfaces these issues before they threaten a release. Isolating flaky tests to run first catches intermittent failures earlier in the cycle, when there is still time to fix them rather than roll back a production release under pressure.

Test Execution Modes: Local, Full Org, and Specified

Salesforce gives you three ways to run tests during a deployment, and picking the wrong one either slows down every release or hides risk you should be seeing. RunSpecifiedTests runs only the classes you name, which is fast but only as safe as your list is complete. RunLocalTests runs every test in the org except those in managed packages, which is the default and most commonly used mode. RunAllTestsInOrg includes managed package tests too, and is almost never necessary outside specific package development scenarios.

Change sets default to running local tests automatically, with no option to run specified tests only. Metadata API deployments give you control over which mode to use, which is one reason teams managing complex orgs move away from change sets entirely. DeployEzee lets you configure test execution mode per deployment pipeline stage, so a quick sandbox validation can run specified tests for speed while the production deploy always runs the full local suite.

The trade-off is honest: specified tests are faster but only protect what you remember to list. Full local test runs take longer, sometimes well over an hour in a large org, but they catch regressions in code nobody touched this sprint. I lean toward full local runs for anything hitting production, even when it costs time, because the alternative is finding out about a regression from a support ticket instead of a failed deploy.

Building a Coverage Strategy That Holds Up at Scale

A coverage strategy that works at 50 Apex classes will not survive at 500. As orgs grow, test run time grows with them, and teams start looking for shortcuts that quietly erode coverage quality. The strategy that holds up long term has a few concrete components rather than a single rule.

Set a per-class minimum above Salesforce's floor, somewhere around 85-90%, and enforce it in your CI pipeline before a deploy is even attempted. Track trigger coverage separately from class coverage since Salesforce treats them as different gates. Isolate known-flaky tests into a watch list and fix or rewrite them rather than letting them linger as a recurring deploy risk.

Finally, treat coverage as a release gate, not a one-time check. Coverage percentages drift as code changes and tests go stale, so a number that passed last quarter is not a guarantee it passes today. Automated pipelines that validate coverage against current thresholds on every deployment attempt, rather than relying on a developer's memory of last month's run, catch this drift before it becomes a failed production release.

Frequently Asked Questions

What is the minimum Apex test coverage required to deploy to Salesforce production?

Salesforce requires a minimum of 75% org-wide Apex test coverage to deploy code containing classes or triggers to production. Every trigger in the org also needs at least one line of test coverage, regardless of the overall percentage. Both conditions must be met simultaneously, and failing either one blocks the deployment entirely.

Why does a Salesforce deployment fail on test coverage even though my new code is fully tested?

Org-wide coverage is calculated across every Apex class and trigger in the org at deploy time, not just the code included in your current release. Untested legacy classes elsewhere in the org can pull the overall percentage below 75% and block your deployment even though your own code is well covered. This is why auditing org-wide coverage regularly, not just before a release, matters.

What is the difference between RunLocalTests and RunSpecifiedTests in a Salesforce deployment?

RunLocalTests executes every Apex test in the org except those belonging to managed packages, and it is the default mode for most deployments. RunSpecifiedTests only runs the test classes you explicitly list, which is faster but only protects against regressions in the tests you remembered to include. Production deployments generally benefit from RunLocalTests despite the longer run time, since it catches issues in code outside the current release scope.

Why do Apex tests pass in a sandbox but fail during a production deployment?

This usually happens because tests depend on data or configuration present in the sandbox but missing or different in production, such as validation rules, required fields, or existing records. Tests written to create their own data through @testSetup methods are far less likely to fail this way than tests that assume specific org state. A sandbox that has drifted from production since its last refresh makes this problem worse.

How do flaky Apex tests affect Salesforce deployment schedules?

Flaky tests pass intermittently due to timing issues, governor limit edge cases, or unpredictable query ordering, and they can fail unexpectedly during a production deployment even after passing in earlier runs. Because Salesforce deployments require all tests to pass, a single flaky test can block or delay an entire release. Running the full test suite on a regular schedule, not only at deploy time, surfaces these tests early enough to fix them before they threaten a production window.