Skip to main content
New tool CRON Expression Builder — preview next run times before you schedule Apex. Open the builder →
Diagram illustrating the Salesforce Tooling API structure and its connection to development tools.
DevOps

Salesforce Tooling API: Developer Guide with Real Examples

The Salesforce Tooling API powers IDEs like VS Code by giving fine-grained access to Apex, LWC, and metadata without a full deployment. Real REST/SOAP examples and when to use it instead of Metadata API.

What exactly is the Salesforce Tooling API?

I've spent a lot of time in the ecosystem, and honestly, the Salesforce Tooling API is one of those features that people hear about but don't always use to its full potential. Most of us are used to the standard apex-callout-solutions/" class="auto-link">REST API for data or the Metadata API for deployments. But the Tooling API is a different beast entirely. It's a specialized set of endpoints designed specifically for developers who need to build tools, manage code, or get deep insights into their org's metadata without the heavy lifting of a full deployment.

Think of it as the "behind-the-scenes" access pass. It gives you fine-grained control over things like Apex classes, triggers, and even your debug logs. If you've ever wondered how VS Code or your favorite Chrome extension manages to show you errors as you type, they're likely using this API under the hood. This is a common topic in any Senior Salesforce Developer interview because it shows you understand the platform's internals.

The features you'll actually use

The Salesforce Tooling API provides a few key things that make life easier for us. Here's what I usually find myself reaching for:

  • Developer-focused objects: You get access to objects like ApexClass, ApexLog, and ApexTestQueueItem that are otherwise a pain to deal with.
  • Programmatic compilation: You can actually create and compile Apex classes on the fly and get back real-time error messages.
  • SOQL for Tooling: You can run queries against tooling-specific objects using the /tooling/query/ endpoint.
  • Speed: It's built for lightweight, "save-and-compile" workflows rather than massive bulk deployments.

Salesforce Tooling API vs Metadata API: Which one wins?

One thing that trips people up is knowing when to use which. I've seen teams try to use the Metadata API for everything, but that's a mistake. Here's the short answer: use the Tooling API when you need speed and granular control over developer artifacts. If you're building an IDE or a tool to manage unit tests, this is your best bet.

On the other hand, stick with the Metadata API for your CI/CD pipelines and full-scale deployments. The Metadata API is meant for moving large chunks of configuration between environments. If you're still weighing the pros and cons of different protocols, checking out this guide on SOAP vs REST might help clarify how these interfaces differ at a high level.

Endpoints and getting started

The good news is that if you know how to authenticate with Salesforce, you're already halfway there. It uses the same OAuth flow as the standard APIs. Once you have your token, you'll hit endpoints that look like this:

/services/data/v60.0/tooling/

Just make sure you're using a recent API version so you don't miss out on newer objects or fields. It's a small detail, but it's one of those things that can cause weird bugs if you forget.

Practical examples with curl

Look, I always find it easier to understand these things with actual code. Here is how you'd query your Apex classes to see what's in your org:

curl -H "Authorization: Bearer <ACCESS_TOKEN>" \
"https://yourInstance.salesforce.com/services/data/v60.0/tooling/query/?q=SELECT+Id,Name+FROM+ApexClass"

And if you want to download a specific debug log body without clicking around the UI, you can do it like this:

curl -L -H "Authorization: Bearer <ACCESS_TOKEN>" \
"https://yourInstance.salesforce.com/services/data/v60.0/tooling/sobjects/ApexLog/<LOG_ID>/Body"

How I used the Salesforce Tooling API in a real project

A few years ago, I was working with a team that had a very specific problem. We were building a custom internal web editor for our developers so they could make quick Apex changes without opening a full IDE. The issue was that the standard deployment process took way too long. Waiting two minutes for a simple syntax check was killing our productivity.

I decided to use the Salesforce Tooling API to solve this. We built a "save-on-compile" feature that worked like this:

  1. When the dev hit save, our backend sent the code to the /sobjects/ApexClass endpoint.
  2. Salesforce would attempt to compile the code immediately.
  3. If there was an error, we'd query the ApexCompileError object to get the exact line and column number.
  4. We'd then highlight that specific line in the web editor so the dev knew exactly what went wrong.

Pro Tip: If you're building something similar, always remember that Tooling API calls count against your org's total API limits. If you have a huge team hitting "save" every five seconds, you'll want to keep an eye on those numbers.

The result? We cut down the feedback loop from minutes to about three seconds. It made a massive difference in how the team worked, and it's a great example of why choosing the right tool for the job matters. This kind of thinking is key to a solid Salesforce API integration strategy.

Common pitfalls to watch out for

It's not all sunshine and rainbows. Here are a few things that might bite you:

  • Permissions: The user running these calls needs "Author Apex" and "Modify All Data" permissions. Don't let that catch you off guard during testing.
  • Rate Limits: As I mentioned, these calls aren't free. Use them wisely and don't spam the API if you don't have to.
  • Versioning: Salesforce updates these APIs frequently. What worked in v50.0 might behave slightly differently in v62.0.

Key Takeaways

  • The Tooling API is built for developer tools and fast, granular metadata access.
  • It's the best choice for "save-and-compile" workflows and log management.
  • Don't use it for bulk migrations - that's what the Metadata API is for.
  • Always keep an eye on your API limits, especially in busy orgs.

So, next time you're building a custom tool or trying to automate a dev workflow, give the Tooling API a look. It's much more powerful than most people realize, and once you get the hang of it, you'll find all sorts of ways to make your development process smoother. Just keep it simple, watch your limits, and you'll be fine.

Frequently asked questions

What is the Salesforce Tooling API?

The Salesforce Tooling API is a REST and SOAP API for building developer tools that interact with Apex code, Lightning components, debug logs, and metadata at a granular level. Unlike the Metadata API, it operates on individual records (a single Apex class, one trigger) without requiring full package deployments — that's why VS Code, Workbench, and Illuminated Cloud all use it under the hood.

What's the difference between Salesforce Tooling API and Metadata API?

The Tooling API works on individual metadata records via REST/SOAP — fast, granular, and ideal for IDE-style operations like editing one Apex class. The Metadata API operates on packages — bundles of XML files — and is built for full deployments and migrations between orgs. Use Tooling for live development; use Metadata for releases.

How do I authenticate with the Salesforce Tooling API?

Same OAuth 2.0 flows as the standard REST API: User-Agent (web app), JWT Bearer (server-to-server), or Web Server (callback-based). Once authenticated, the Tooling endpoint is `https://yourInstance.my.salesforce.com/services/data/vXX.0/tooling/` — note the `/tooling/` segment that distinguishes it from the standard REST API base.

What can you do with the Salesforce Tooling API?

Common operations: compile and save Apex classes, run anonymous Apex (ExecuteAnonymous), retrieve and delete debug logs (ApexLog), query test results (ApexTestResult, ApexCodeCoverage), manipulate Custom Fields and Validation Rules without a deployment, manage SymbolTable for code completion, and execute SOQL against tooling-only objects like ApexClass, ApexTrigger, AuraDefinition, and FlowDefinition.

What is the API rate limit for the Tooling API?

The Tooling API counts against the same per-org daily API limit as the standard REST API (typically 15,000-1,000,000+ requests/day depending on edition). Bulk operations should batch requests using the composite endpoint to minimize the count. There's no separate Tooling-specific limit, so a chatty IDE plugin can blow through limits if it polls aggressively.

Can I run anonymous Apex via the Tooling API?

Yes. POST to /services/data/vXX.0/tooling/executeAnonymous/?anonymousBody=YourCode — the response includes compile status and any uncaught exceptions. This is how SFDX runs `sfdx force:apex:execute` and how VS Code's 'Execute Anonymous Apex' command works. Note: governor limits and 'with sharing' rules still apply.

Is the Salesforce Tooling API the same as SFDX?

No — SFDX (the Salesforce CLI) uses the Tooling API and the Metadata API together. SFDX commands like sfdx force:source:deploy primarily talk to Metadata API; sfdx force:apex:test:run uses Tooling API to query test results. Most third-party Salesforce IDEs are built on top of Tooling API directly.

Newsletter

One email every Tuesday

New guides, tool updates, and the release-note changes that break things.

No spam. Unsubscribe in one click.

Comments

Loading comments...

Leave a Comment