Use the Salesforce Tooling API to query code coverage data for Apex classes and identify classes below the required coverage threshold programmatically
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 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp