Salesforce Dictionary — Free Salesforce GlossarySalesforce Dictionary

Code Coverage

Development🟡 Intermediate

Definition

Code Coverage in Salesforce refers to the percentage of Apex code lines that are executed by test methods. Salesforce requires a minimum of 75% overall code coverage across the org for deploying Apex to production, and each trigger must have at least 1% coverage. Code coverage is measured by running Apex test classes and is tracked on the Apex Classes and Apex Test Execution Setup pages.

Real-World Example

a senior developer at TerraForm Tech recently implemented Code Coverage to solve a complex business requirement that cannot be addressed with declarative tools alone. They implement Code Coverage with proper error handling, write 98% test coverage, and document the solution for future maintainers. The code passes security review on the first attempt.

Why Code Coverage Matters

Code Coverage in Salesforce measures the percentage of executable Apex code lines that are run by test methods. Salesforce calculates coverage by running Apex tests and tracking which lines of each class and trigger are exercised. The coverage requirement to deploy Apex to production is at least 75% across all Apex code in the org, and every trigger must have at least 1% coverage individually. Code Coverage is shown in the Apex Classes setup page, the Apex Test Execution page, and through the Tooling API.

The 75% threshold is a minimum, not a target. Real-world quality depends on whether tests actually verify behavior, not just whether they execute code. A test that runs every line of a method without checking the result still contributes to coverage but provides no quality assurance. Mature Salesforce teams aim for higher coverage (85-90%+) and write tests that include assertions for both happy-path and error scenarios. Code coverage also has gotchas: lines covered include 'reached' lines but not necessarily lines that produced correct behavior, so coverage alone is not a measure of test quality.

How Organizations Use Code Coverage

  • TerraForm TechMaintains an internal target of 90% code coverage across all Apex, well above the Salesforce minimum of 75%. The higher target is enforced through their CI/CD pipeline, which fails any deployment that drops below the threshold.
  • CodeBridgeDiscovered that a class had 80% coverage but every test was missing assertions. The coverage number was meeting the deployment requirement but the tests were verifying nothing. They added assertions to all tests as part of a quality push.
  • Quantum LabsReports code coverage per class on a dashboard so the team can quickly see which classes have low coverage and need attention. Classes with critical business logic and low coverage are prioritized for additional test writing.

🧠 Test Your Knowledge

1. What is the minimum code coverage required to deploy Apex to production?

2. Why is coverage alone not a sufficient measure of test quality?

3. What is a good target for code coverage in mature teams?

See something that could be improved?

Suggest an Edit