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

  1. Authenticate to the Salesforce org and confirm the Tooling API base URL: /services/data/vXX.0/tooling/
  2. GET /services/data/vXX.0/tooling/query/?q=SELECT+ApexClassOrTriggerId,ApexClassOrTrigger.Name,NumLinesCovered,NumLinesUncovered+FROM+ApexCodeCoverageAggregate to retrieve aggregate coverage per class
  3. Compute coverage percentage as NumLinesCovered / (NumLinesCovered + NumLinesUncovered) * 100 for each row; filter for classes below 75% (the Salesforce deployment threshold)
  4. 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
  5. Output a report of class name, covered lines, uncovered lines, and percentage to guide remediation

Known gotchas

Related routes

Query the Salesforce Tooling API to retrieve Apex code coverage data and identify under-covered classes
developer.salesforce.com · 6 steps · unrated
Handle Salesforce Apex governor limits proactively using Limits class checks and defensive coding patterns in bulk trigger contexts
developer.salesforce.com · 6 steps · unrated
Write a Salesforce Batch Apex class to process large datasets in chunks with start, execute, and finish methods
developer.salesforce.com · 6 steps · unrated

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?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans