Use the Salesforce Tooling API to query code coverage data for Apex classes and identify classes below the required coverage threshold programmatically
domain: salesforce.com · 5 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 salesforce.com, checked against official docs, with linked verified routes.
Steps
Authenticate to the Salesforce org and confirm the Tooling API base URL: /services/data/vXX.0/tooling/
GET /services/data/vXX.0/tooling/query/?q=SELECT+ApexClassOrTriggerId,ApexClassOrTrigger.Name,NumLinesCovered,NumLinesUncovered+FROM+ApexCodeCoverageAggregate to retrieve aggregate coverage per class
Compute coverage percentage as NumLinesCovered / (NumLinesCovered + NumLinesUncovered) * 100 for each row; filter for classes below 75% (the Salesforce deployment threshold)
For classes below threshold, GET /services/data/vXX.0/tooling/query/?q=SELECT+Coverage,TestMethodName+FROM+ApexCodeCoverage+WHERE+ApexClassOrTriggerId='{classId}' to see which test methods contribute coverage and which lines are uncovered
Output a report of class name, covered lines, uncovered lines, and percentage to guide remediation
Known gotchas
ApexCodeCoverageAggregate reflects coverage from the most recent test run in the org — if tests have not been run recently, the data may be stale and not reflect current code; trigger a test run via POST /services/data/vXX.0/tooling/runTestsAsynchronous/ first
The Tooling API query endpoint is separate from the standard query endpoint; sending Tooling API SOQL to the regular /query/ endpoint returns an 'object not found' error for Tooling API objects
Coverage data is stored per sandbox/production org independently; coverage figures in a sandbox do not predict coverage in production if the code differs
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?