SyncOnAI360

Use case: Apex coverage

How to raise Apex test coverage above 75%, with tests that mean something.

Find the classes that need tests, generate tests in your org's own patterns, and know before deploy day whether a change will pass Salesforce's coverage gate.

OpportunityWonHandler.cls

Apex Logic · Component builder

  • For each Opportunity in trigger.new
  • If StageName changed to Closed Won
  • Collect AccountId
  • Query Accounts once, outside the loop
  • Update Account.Last_Won_Date__c

Edit: move the query back inside the loop

Compiles. Test class included in the proposal.

In one paragraph

Raising Apex coverage with SyncOnAI 360 means reading coverage from the org's last test run, finding the classes the audit flags for missing or weak tests, generating tests around the org's own patterns, and shipping them as validated proposals, with every proposal checked against Salesforce's 75% production gate.

Salesforce's production coverage gate
75%Salesforce's production coverage gate
Proposal with Apex runs a coverage check
EveryProposal with Apex runs a coverage check
Shown when no test run exists, never 0%
Not recordedShown when no test run exists, never 0%
Change for a class and its test
1Change for a class and its test

01The problem

Why coverage becomes a deploy-day emergency

Coverage is ignored until a production deploy fails the gate. Then someone writes tests that execute lines without checking anything, just to get over the bar.

  1. 01

    Found at deploy

    The coverage failure appears in the release window.

  2. 02

    Hollow tests

    Tests written to execute lines, not to check behaviour.

  3. 03

    No priority

    Nobody knows which classes matter most.

  4. 04

    Unknown baseline

    Coverage figures are old or missing.

02measure

Where does the Apex coverage figure come from?

From the org's last recorded test run. If no run is recorded, the page says Not recorded rather than 0%. Run the tests in Salesforce or ask the chat to run them, refresh the org, and the figure updates.

  • From the last test run
  • Not recorded, never a false zero
  • Run tests from the chat

OpportunityWonHandler.cls

Apex Logic · Component builder

  • For each Opportunity in trigger.new
  • If StageName changed to Closed Won
  • Collect AccountId
  • Query Accounts once, outside the loop
  • Update Account.Last_Won_Date__c

Edit: move the query back inside the loop

Compiles. Test class included in the proposal.

03find

Which classes should get tests first?

The audit's Apex section flags missing or weak tests alongside code-quality issues such as SOQL in loops and hardcoded ids, each opened to the source lines, with severity and effort. Start with severe, quick items rather than chasing the overall percentage.

  • Uncovered classes flagged
  • Code-quality issues beside them
  • Severity and effort

Org Audit

Acme Production · last run 6 minutes ago

Grade C

C

74 / 100

Fair, technical debt accumulating

Automation & Flows

64

Permissions & Security

71

Apex & Code

78

Fields & Data Quality

82

Limits & Performance

91

Change Intelligence

69

55 checks run · 37 open findings · 2 checks skipped, with the reason shown

04write

How do you generate Apex tests that fit the org?

Ask the Apex Engineer agent or the chat to write tests for a class. Generated Apex comes with tests built around the org's own patterns, and Apex Logic refuses edits that would not compile.

Review the test like any other code before it ships: the goal is behaviour checked, not lines executed.

  • Tests in the org's patterns
  • Compile-checked edits
  • Reviewed before shipping

OpportunityWonHandler.cls

Apex Logic · Component builder

  • For each Opportunity in trigger.new
  • If StageName changed to Closed Won
  • Collect AccountId
  • Query Accounts once, outside the loop
  • Update Account.Last_Won_Date__c

Edit: move the query back inside the loop

Compiles. Test class included in the proposal.

05gate

Will the deploy pass Salesforce's coverage gate?

Every proposal containing Apex runs a test coverage check. If it carries its own tests, Salesforce runs those and needs each deployed class covered; if it carries none, Salesforce runs every test in the org and needs the overall average at the bar. The check warns before deploy day.

  • Coverage checked on every proposal
  • Both Salesforce paths explained
  • Warned before deploy day

Proposal: Case intake fault handling

Acme Production

Checks passed
  • Validated against the org without changing it
  • No component outside the change is modified
  • Apex tests pass, coverage 81%
  • No freeze window in effect
  • Policy: production requires a second admin

Blast radius

  • 2 Flows read Case.Priority
  • 1 report filters on it
  • Case_Intake_Route assigns from it

Risk: medium

06plan

How do you make coverage planned work?

Turn coverage findings into work items on a project board, with their effort, so raising coverage happens steadily between releases. A component can be proposed together with its Apex controller and its test as one change.

  • Findings to work items
  • Steady progress
  • Class and test together

Service Transformation

Projects · Board · Sprint 7

To do 2

Remove 14 unused Case fields

From audit

Consolidate Account triggers

Apex

In progress 1

Fault paths on intake Flows

From audit

In review 1

APAC routing for Service

Flow

Done 1

Retire Process Builder on Lead

Release 24.3

Work items link to the proposals and deploys that delivered them

07quality

What makes an Apex test worth keeping?

A test that checks behaviour: it sets up data, runs the code and asserts the result, including the failure cases. Tests that only execute lines raise the percentage without protecting anything, and they break the first time someone refactors.

Review generated tests the way you would review a colleague's: check that each asserts something meaningful about the class it covers before it ships.

  • Assert behaviour, not lines
  • Cover failure cases
  • Review before shipping

OpportunityWonHandler.cls

Apex Logic · Component builder

  • For each Opportunity in trigger.new
  • If StageName changed to Closed Won
  • Collect AccountId
  • Query Accounts once, outside the loop
  • Update Account.Last_Won_Date__c

Edit: move the query back inside the loop

Compiles. Test class included in the proposal.

08How it works

How to raise Apex coverage

Measure, prioritise, write, check, ship.

  1. 01

    Measure

    Run tests and refresh for a current figure.

  2. 02

    Prioritise

    Start with flagged, severe classes.

  3. 03

    Write

    Generate tests in the org's patterns and review them.

  4. 04

    Check

    Read the coverage check on the proposal.

  5. 05

    Ship

    Validate, approve and deploy.

09Checklist

Apex coverage checklist

  • Run the org's tests and refresh so the coverage figure is current.
  • List the classes the audit flags for missing or weak tests.
  • Start with severe, quick items rather than the overall percentage.
  • Make sure each new test asserts behaviour, including failure cases.
  • Propose each class with its test as one change where possible.
  • Read the coverage check on the proposal before deploy day.
  • Turn the remaining gaps into planned work items.

10Before and after

Apex coverage, rushed versus planned

Without

With SyncOnAI 360

Coverage failure in the release window

Warned on the proposal

Tests that only execute lines

Tests in the org's patterns, reviewed

Old or missing figures

Last run shown, or Not recorded

No priority

Severity and effort per class

12Questions

Frequently asked questions

75% to deploy Apex to production.

No test run is recorded for the org. Run the tests and refresh.

Yes. Ask the chat to run them, then refresh the org.

Yes, around the org's own patterns. Review them before they ship.

Every proposal with Apex runs a coverage check that warns before deploy day.

Yes, such as SOQL in loops and hardcoded ids, each opened to the source lines.

Yes. A class or component can be proposed with its test as one change.

Yes. Every plan includes every feature.

Coverage comes from the org's last test run, and the audit flags classes with missing or weak tests.

Start in 5 minutes. No card required.

Connect your Salesforce org. Run your first health scan. Ask your first question. See what you've been missing.

  • Anthropic
  • OpenAI