Sub topic 2
The 75% Requirement and the Rules for Triggers
This chapter assumes you can read basic Apex (classes, methods, SOQL, DML) and know what a trigger is. You also need access to a sandbox, scratch org, or Developer Edition org. Here you learn what Salesforce enforces at deployment time and where those rules stop.
The production rule
When you deploy Apex to a production org, Salesforce runs tests and checks coverage. The rule has three parts:
- Overall coverage across all Apex in the org must be at least 75%.
- Every test that runs in the deployment must pass.
- Every trigger must have some coverage. A trigger at 0% blocks the deployment.
The 75% figure is an org-wide total. It is not a per-class rule. A class at 40% can deploy if the rest of the org's Apex raises the total above 75%.
The trigger rule is separate. Salesforce requires at least 1% coverage on each trigger, which means at least one line of it must run during tests. In practice, treat this as a floor. A trigger that holds business logic needs real tests.
Salesforce can also set a per-class requirement during certain packaging workflows. For example, managed package publishing has its own stricter expectations. Check the current Salesforce documentation for your release before you rely on a specific number.
What the deployment check does
A failing test blocks a deployment even when coverage is high. A passing suite with low coverage also blocks it. Both conditions must hold.
A worked example
Suppose your org has 1,000 executable lines of Apex. Salesforce counts a line as covered if a test ran it. You need at least 750 covered lines.
| Component | Lines | Covered | Coverage |
|---|---|---|---|
| Services and helpers | 800 | 640 | 80% |
| Triggers and handlers | 100 | 60 | 60% |
| Batch classes | 100 | 20 | 20% |
| Org total | 1,000 | 720 | 72% |
The total is 72%, so this deployment fails even though the first row looks healthy. Covering 30 more lines in the batch classes would raise the total to 75%. Notice that the failure comes from the sum. No single row is the rule.
Rules for triggers
Triggers get extra attention for two reasons.
- Each trigger must have at least 1% coverage, so every trigger needs a test that fires it.
- A trigger fires in bulk. Salesforce can pass up to 200 records in one batch, so a test that inserts one record leaves the bulk path untested.
A common pattern keeps the trigger thin and moves the logic into a handler class. Coverage then comes from testing the handler directly and from a small test that fires the trigger.
What does not count
- Test classes do not count toward the total. Lines in classes annotated with
@isTestare excluded from the calculation. - Only lines the platform treats as executable count. Comments and blank lines do not.
- Deploying to a sandbox or scratch org does not enforce the 75% rule. Only production deployments do. Do not wait for production to find the gap.
Exercise
Your org has 2,000 executable lines and 1,450 are covered. A trigger in the deployment has 0% coverage. Does the deployment succeed? Explain.
Show answer
No. Org coverage is 1,450 / 2,000 = 72.5%, which is below 75%. The 0% trigger also fails the rule that every trigger needs coverage. Either condition alone blocks the deployment.
Exercise
A class has 30% coverage, but org-wide coverage is 82%, all tests pass, and every trigger is covered. Can you deploy to production?
Show answer
Yes. The 75% requirement applies to org-wide coverage, not to each class. The weak class is still a risk and should get tests, but it does not block this deployment.