Loading

Salesforce Apex: Code Coverage Drops Below 75% During Deployment — Why Estimates Differ from Deployment Results

Publiceringsdatum: Jun 22, 2026
Beskrivning

When deploying Salesforce metadata components (such as Apex classes or triggers), developers may encounter a code coverage error during deployment even though the organization's estimated code coverage appears to be above the required 75% threshold. This discrepancy occurs because the code coverage percentage is recalculated during deployment based on all classes in the org plus the classes being deployed, which can cause the coverage percentage to drop below 75%.


Note: As of Winter '14, the link previously named "Calculate your organization's code coverage" was renamed to "Estimate your organization's code coverage."

Lösning

Why Estimated Coverage Differs from Deployment Coverage

The "Estimate your organization's code coverage" link in Setup calculates coverage based on the existing classes in your org at that point in time. During deployment, Salesforce recalculates coverage based on the total number of classes in the org PLUS all the classes included in the current deployment package. If the deployed classes do not have corresponding test classes, the total class count increases while covered lines remain the same, causing the coverage percentage to drop.

Example

If your org has 100 classes at 80% coverage and you deploy 50 new classes without test coverage, the new coverage is calculated across 150 classes. The coverage percentage decreases because the 50 new classes are counted in the denominator but are not covered by any test class.

Note: Do not rely on the "Estimate your organization's code coverage" link during deployment. The calculation during deployment is different from the pre-deployment estimate because it includes the new components being deployed. Even a small deployment can impact the test code coverage calculation.

How to Resolve Code Coverage Errors During Deployment

  1. Identify test classes that have code coverage under 75% and work on increasing their coverage above 75%.
  2. Identify Apex classes that do not have any associated test classes, and create test classes for them.
  3. Push the updated test classes in your deployment until the overall test code coverage in the org exceeds 75%.

 

Here are the list of components that trigger "run all tests" during deployment and impact the test code coverage 

Running Tests in a deployment

How Code Coverage works

Testing Best practices

Knowledge-artikelnummer

000385908

 
Laddar
Salesforce Help | Article