How do developer IDEs leverage the Tooling API to compile code, run tests, and inspect debug logs?
Answer
Basics: The Metadata API is coarse-grained: you retrieve or deploy whole components. IDEs need small, fast, interactive operations such as "compile this one class and tell me the errors", "run these tests and stream results" or "show me the log for that run". The Tooling API fills that gap. Endpoint: /services/data/vXX.0/tooling/. The Developer Console is built on it, and so are the Apex Replay Debugger and test runs in VS Code (via the Salesforce CLI).
How it works:
- Compile and save: tools create a
MetadataContainer, addApexClassMember/ApexTriggerMemberrecords holding the new body, then post aContainerAsyncRequest. Salesforce compiles, returnsCompilerErrors, and optionally deploys (IsCheckOnly= true validates only). - Run anonymous Apex:
GET /tooling/executeAnonymous?anonymousBody=.... - Tests:
runTestsAsynchronousqueues anApexTestQueueItemper class; results land inApexTestResult, coverage inApexCodeCoverageandApexCodeCoverageAggregate.runTestsSynchronousis for a single class. - Debugging: create a
DebugLeveland aTraceFlagfor a user, run the code, then queryApexLogand fetch/sobjects/ApexLog/<id>/Body.
Advanced / deep dive: Tooling objects are real sObjects, so you can use SOQL (/tooling/query), describe calls and DML-style create/update/delete, but many relationship queries are restricted. The CLI (sf apex run test, sf apex get log, sf apex tail log) wraps these calls; log tailing uses Streaming. Tooling API is not a deployment pipeline: production deployments should still go through Metadata API (Salesforce CLI ) with test-level controls. Access requires the "API Enabled" and "Author Apex" permissions, and viewing other users' logs needs "View All Data" or "Manage Users".