Query the Salesforce Tooling API to retrieve Apex code coverage data and identify under-covered classes
domain: developer.salesforce.com · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗
In-depth guide
Salesforce Bulk API 2.0 limits — the full failure-mode walkthrough related to developer.salesforce.com, checked against official docs, with linked verified routes.
Steps
Authenticate with a Salesforce session and target /services/data/vXX.0/tooling/query/
Query ApexCodeCoverageAggregate with fields NumLinesCovered and NumLinesUncovered filtered to the classes you care about
Calculate coverage percentage as NumLinesCovered / (NumLinesCovered + NumLinesUncovered)
Cross-reference with the ApexClass object to resolve class names from ApexClassOrTriggerId
Page through results using nextRecordsUrl if the org has many classes
Report classes below 75% coverage threshold and surface the specific uncovered lines via ApexCodeCoverage
Known gotchas
Coverage data in ApexCodeCoverageAggregate reflects the last full test run; stale data appears if tests have not been re-executed after recent code changes
The Tooling API uses its own query endpoint separate from the standard SOQL endpoint; mixing them returns an error
Coverage percentages can momentarily read 0% for new classes until at least one test that covers them has been executed
Give your agent this knowledge — and 15,600+ more routes
One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp
Need this verified for your stack — or a route we don't have yet?