Metadata API deploys and retrieves customizations in bulk, as a zip of XML files, and it's what Salesforce CLI and the VS Code extensions use to move source between orgs. Tooling API reaches the same metadata one element at a time, and lets you query much of it with SOQL (Salesforce Object Query Language). Salesforce's own rule of thumb is that smaller retrieves make Tooling API "a better fit for developing interactive applications."
So the short answer is this. If a pipeline is moving a release, use Metadata API. If a person or a tool is waiting on one answer, such as a field's type or a class's code coverage, use Tooling API. Most serious builds use both.
For a SaaS company whose product ships inside Salesforce as a managed package, this choice decides how fast releases reach customers. It shows up in four places. Those are how you build and version the package, how your CI deploys it, how you check coverage before the security review, and how the package configures itself in a customer's org. Appnigma builds native Salesforce apps for SaaS teams, and its marketplace apps projects cover the managed package, the listing and security review preparation, so these choices are made for you.
Updated October 2026. Checked against Salesforce's Metadata API and Tooling API guides. It corrects two earlier claims (Tooling API concurrency, and how IDEs save Apex), notes that Workflow Rules lost support on December 31, 2025, and adds Tooling query examples, the Apex Metadata namespace for packages, and more deploy limits.
Metadata API and Tooling API side by side
| Metadata API | Tooling API | |
|---|---|---|
| Unit of work | A zip of files, listed in a package.xml manifest | A single element, exposed as a queryable object |
| Query with SOQL | No | Yes, for many metadata types |
| Change one element in a complex type | Retrieve, edit and redeploy the whole component | Change just that element |
| Concurrency | One deployment runs at a time per org, the rest queue | Normal API calls under org limits, but an outstanding Apex save blocks other saves |
| Interfaces | SOAP, plus a REST deploy endpoint | SOAP and REST |
| Typical caller | Salesforce CLI, CI pipelines, packaging | Developer tools, admin utilities, coverage reports |
Salesforce says Tooling API "can be easier to use than Metadata API" because it changes one element within a complex type. Through Metadata API, editing a single picklist value means retrieving the object, changing the file and deploying it back.
Record syncs your product runs, such as accounts or invoices, belong on Bulk API 2.0 for record data or REST, since Metadata API "doesn't work directly with business data," per its introduction.
When should you use the Tooling API instead of the Metadata API?
Use Tooling API when you need fine-grained access, per Salesforce's When to Use Tooling API page. In practice that covers four kinds of work.
- Reading what exists without a retrieve. A SOQL query on FieldDefinition or EntityDefinition answers "does this field exist and what type is it" without pulling a zip.
- Test and coverage reporting. ApexCodeCoverageAggregate and ApexOrgWideCoverage return coverage per class and for the whole org.
- Debugging. TraceFlag turns on debug logs, which expire within 24 hours, and ApexLog returns them.
- Interactive tools. Editors and admin utilities that change one thing at a time.
Use Metadata API for release pipelines, org-to-org migration, a full metadata snapshot, and anything that has to succeed or fail as a unit. Salesforce describes deploy() and retrieve() as "best fit for the final stages of development."
Metadata API deploy limits to plan a release around
These come from the deploy() reference. Salesforce notes that limits can change without notice.
| Limit | Value |
|---|---|
| Files, unlocked or second-generation (2GP) package | 10,000 |
| Files, first-generation (1GP) managed package | 35,000, only for 1GP packages that passed the security review |
| Compressed zip | About 39 MB |
| Uncompressed folder | About 600 MB |
| Custom fields per deployment | 45,000 |
| Deployment status kept | 30 days |
| Running deployments per org | One, others queue |
| Quick deploy window | Within 10 days of a successful validation |
The 39 MB cap exists because Metadata API base64-encodes the zip, which adds about 22%, and the encoded payload can't exceed 50 MB. Size against 39 MB, not 50.
The 35,000-file allowance doesn't carry over to 2GP. If you're planning a 2GP package or migrating a 1GP package to 2GP, 10,000 files is the number to design against. Our guide to 1GP vs 2GP managed packages covers the rest of that choice.
Three deploy settings matter in production. rollbackOnError must be true. checkOnly validates without saving, and a validation from the last 10 days can then be quick deployed with deployRecentValidation(). From API 65.0, a deployment in Finalizing Deploy status can't be cancelled.
Metadata API also has a REST route, POST /services/data/vXX.0/metadata/deployRequest, per the REST deploy page. Salesforce CLI's project deploy start uses the Metadata SOAP API by default and switches to REST with sf config set org-metadata-rest-deploy true, which Salesforce says "offers faster deployment."
Salesforce Tooling API query examples
Tooling API queries go to the tooling endpoint, /services/data/vXX.X/tooling/query/?q=, per the REST resources page. From Salesforce CLI, add --use-tooling-api to a query.
List the fields on an object and their types:
sf data query --use-tooling-api --query "SELECT QualifiedApiName, DataType FROM FieldDefinition WHERE EntityDefinition.QualifiedApiName = 'Account'"Org-wide Apex code coverage:
sf data query --use-tooling-api --query "SELECT PercentCovered FROM ApexOrgWideCoverage"Covered and uncovered lines per class:
sf data query --use-tooling-api --query "SELECT ApexClassOrTrigger.Name, NumLinesCovered, NumLinesUncovered FROM ApexCodeCoverageAggregate"FieldDefinition queries must filter on EntityDefinition.QualifiedApiName, per the FieldDefinition reference. The coverage objects need the View Setup and Configuration permission from API 49.0.
Some Tooling objects take only part of SOQL. EntityDefinition, FieldDefinition and EntityParticle don't support COUNT(), GROUP BY, LIMIT, OFFSET, OR, NOT or INCLUDES, per the SOQL limitations page. LIMIT is the dangerous one, because it's ignored and the query returns a wrong result rather than an error.
Saving Apex through MetadataContainer
Compiling Apex through Tooling API uses three objects together: MetadataContainer, ApexClassMember and ContainerAsyncRequest. You create a container, add a member holding the new class body, submit an async request, and poll until it completes. Salesforce's sample polls every 2 seconds.
It works in development orgs. Per the ApexClass reference, Apex classes and triggers can't be created, edited or deleted in a production org. Saves are serialized too: "If there is an outstanding save request, all updates, inserts, and deployments fail," per the ContainerAsyncRequest reference. The member objects need View All Data plus Author Apex.
Which API each managed package job uses
When a SaaS team builds and ships a managed package, Metadata API and Tooling API each handle different jobs, from creating a package version to configuring the package in a customer's org.
| Job | What does it |
|---|---|
| Move source into scratch orgs and sandboxes | Salesforce CLI over Metadata API |
| Create a 2GP package version | sf package version create, recorded in Tooling API as Package2VersionCreateRequest |
| Check coverage before promoting a version | Tooling API coverage objects. Promotion needs 75% Apex coverage |
| Configure the package after install | Apex Metadata namespace in a post install script |
| Find what depends on a component | MetadataComponentDependency, a Tooling object still in Beta |
The coverage gate is easy to miss. Per Salesforce's 2GP code coverage page, beta versions built without computing coverage can't be promoted, so run sf package version create with --code-coverage on any build you might release. A Salesforce Code Analyzer scan before submission belongs in the same release step.
Deploying metadata from Apex inside a managed package
Apex has its own Metadata namespace. Metadata.Operations.enqueueDeployment() deploys asynchronously and Metadata.Operations.retrieve() reads synchronously, per the Apex guide. It's how a package sets itself up in a customer's org, including from a post install script. It's narrower than Metadata API in four ways.
- It supports only custom metadata type records and page layouts.
- It can create and update, but it can't delete.
- Until the package passes the security review, its Apex can't deploy metadata unless the customer turns on "Deploy Metadata from Non-Certified Package Versions via Apex" in Apex Settings. That matters during pilots.
- The package description must say the package can change metadata outside its namespace, and Salesforce checks that notice during review, per the security considerations page. Our guide to what the security review checks covers the rest.
Mistakes that slow down Salesforce deployments
- Parallel CI deploys to one org. Only one deployment runs at a time, and queued ones "are not necessarily executed in the order in which they were submitted." Fanning out jobs adds queue time and can deploy out of order.
- A zip just over 39 MB. It fails at upload even though the stated SOAP limit is 50 MB.
- Designing a 2GP package around 35,000 files. That figure only applies to security-reviewed 1GP packages.
- Trusting LIMIT on FieldDefinition. It's ignored, so a "first 10 fields" query returns something else.
- Two Apex saves at once through Tooling API. The second fails while the first is still outstanding.
- Deploying during a Salesforce service upgrade. File-based deployments restart from the beginning when the service returns, per the slow deployments page. That includes package version creation.
- Calling executeAnonymous from a managed package. Salesforce blocks /executeAnonymous requests from managed package components.
- Building new automation as Workflow Rules. Salesforce ended support for Workflow Rules and Process Builder on December 31, 2025. Tooling API can still read WorkflowRule, but new automation belongs in Flow.
Frequently Asked Questions
What is the difference between Metadata API and Tooling API?
Metadata API deploys customizations in bulk as zipped XML, for releases. Tooling API reads and changes single elements and supports SOQL, for developer tools.
Can I query metadata with SOQL?
Yes, through Tooling API, for many metadata types. Metadata API has no SOQL interface.
What is the maximum Metadata API deployment size?
About 39 MB compressed and about 600 MB uncompressed, with up to 10,000 files and 45,000 custom fields per deployment.
How many files can a Salesforce package contain?
10,000 for unlocked and second-generation managed packages. 35,000 for first-generation managed packages that passed the security review.
Can Salesforce run multiple deployments at once?
No. You can start several, but only one runs per org and the rest queue, not necessarily in the order submitted.
Does Salesforce CLI use Metadata API or Tooling API?
Deploys and retrieves use Metadata API, SOAP by default or REST if enabled. Queries can use Tooling API with --use-tooling-api.
How do I save an Apex class without deploying?
Through Tooling API in a development org, with MetadataContainer, ApexClassMember and ContainerAsyncRequest. Apex can't be created or edited this way in production.
How long is Metadata API deployment status available?
30 days.
Can Appnigma build our managed package and set up the deployment?
Yes. Appnigma builds native Salesforce apps for SaaS companies, including the managed package, the listing and security review preparation. Salesforce decides review outcomes and timing.
Related Articles
- How to create a managed package in Salesforce
- 1GP to 2GP managed package migration
- Salesforce Code Analyzer guide
- Authenticate your tool with an External Client App
Sources
- Introduction to Metadata API, Salesforce Developers
- deploy(), Metadata API Developer Guide
- Declarative (file-based) Metadata API calls, Metadata API Developer Guide
- Deploy metadata with Apex testing using REST, Metadata API Developer Guide
- Deploy metadata with REST API in Salesforce CLI, Metadata API Developer Guide
- When to use Tooling API, Tooling API Developer Guide
- SOQL operation limitations, Tooling API Developer Guide
- ContainerAsyncRequest, Tooling API Developer Guide
- Code coverage for second-generation managed packages, Salesforce Developers
- Retrieving and deploying metadata in Apex, Apex Developer Guide
- Workflow Rules and Process Builder end of support, Salesforce Help