Code coverage measures how much of an org's Apex code runs during tests. Salesforce requires at least 75% Apex coverage to deploy to production, and every trigger needs some coverage, so low coverage blocks releases at the worst possible moment. Coverage is also a quality signal: untested classes and branches are where defects hide. The goal is meaningful tests that exercise real behavior, not lines added only to raise the number.
Common Coverage Problems
- Blocked deployments. A release fails because overall coverage dropped below the requirement or a trigger has no coverage.
- Untested code. Classes and triggers with no test at all, often from old projects.
- Padded coverage. Tests or code written to execute lines without checking any results, which raises the number without testing behavior.
- Failing tests. Tests that fail because of data assumptions or changes elsewhere in the org, which also block deployment.
How to Approach Coverage
- Run the tests and measure coverage for each class and trigger, line by line.
- Fix failing tests first, since failures block deployments regardless of coverage.
- Target the biggest gaps: untested classes and triggers, and large uncovered blocks in critical code.
- Write tests with assertions that check results, using test data the tests create themselves.
- Monitor continuously. Check coverage after each new snapshot or release and alert when coverage falls below your thresholds.
How Snapshot Helps
- Apex Code Coverage Report: runs selected tests and shows test outcomes, errors, coverage percentages, and covered and uncovered executable lines for each class and trigger. Check All includes untested classes and triggers, and Code Coverage shows line-by-line detail. Manage Levels sets Low, Medium, and High Coverage boundaries for color coding and conditional scheduled alerts. In the Editing Palette, Coverage Improvement and Multiple Improvements propose AI-written test changes to compare, save, and deploy.
- Apex Code Quality Report: static analysis of the same classes and triggers, which complements coverage results.
Coverage from selected tests does not establish deployment readiness or correct business behavior. Improved tests take effect only after deployment and a new test run.
Metadata Types Involved
-
ApexClass: classes under test and the test classes themselves. -
ApexTrigger: triggers, which each need test coverage for production deployment. -
ApexTestSuite: reusable groups of test classes to run together.
Common Questions
What code coverage does Salesforce require?
At least 75% of Apex code must be covered by tests to deploy to production, all tests must pass, and every trigger must have some coverage.
Is 75% coverage good enough?
75% is the minimum to deploy. Many teams aim higher for critical code, and the quality of assertions matters more than the percentage.
Why did coverage drop when no code changed?
Tests can start failing, or cover fewer lines, when data, configuration, or other code changes. Rerun tests after major configuration changes, not only after code changes.