Beginner 10 min read

Code Coverage Requirements

By the end of this lesson, you'll be able to:

  • Explain Salesforce's 75% code coverage requirement for production deployments
  • Distinguish meaningful coverage from coverage written only to hit the number

Prerequisites: Assertions and Common Patterns

The 75% rule

Deploying Apex to production requires overall org coverage of at least 75%, calculated in aggregate across all Apex — not per class. Every trigger needs at least some coverage too. Coverage is a deployment gate, not a design goal in itself.

Coverage isn't the same as correctness

A test with no assertions at all can still contribute 100% coverage of the lines it executes — it only proves the code ran without throwing an exception, nothing more. Meaningful tests assert real expected outcomes, not just "did it run without crashing."

Identical coverage, very different value

// Executes every line — counts toward coverage — but proves almost nothing
@isTest
static void weakTest() {
    AccountHelper.greet('Ada');
}

// Same lines executed, but actually verifies the behavior
@isTest
static void strongTest() {
    String result = AccountHelper.greet('Ada');
    System.assertEquals('Hello, Ada!', result);
}

Both methods report identical code coverage — the difference is that only the second one would actually fail if greet() broke.

Exercise

Explain in a comment why a class with 100% code coverage could still ship a serious bug.

Show hint

Think about what coverage percentage actually measures versus what assertions verify.

APEX

Code Coverage Requirements — Quick Check

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

2. A test with no assertions can still count toward code coverage.

3. What does code coverage actually measure?

Log in to submit the quiz and save your score.

My Notes

Log in to keep private notes on this lesson.

Questions about this lesson

No questions yet — be the first to ask.

Log in to ask a question about this lesson.

Summary

Salesforce requires at least 75% aggregate Apex code coverage (with every trigger having some coverage) before you can deploy to production — but coverage percentage alone doesn't prove your tests are actually any good.