What capabilities does the Metadata API provide for automating continuous integration and deployment pipelines?
Answer
Basics: Metadata is the "configuration and code" of an org, separate from its data. The Metadata API lets tools move that between sandboxes, scratch orgs, version control and production, replacing manual clicking. It is SOAP-based (with a REST variant for deploy and retrieve) and asynchronous: you start a deploy and poll for status.
How it works:
- Describe the contents in a package.xml manifest (types and members, or
*wildcards), or use source-format project files that the CLI converts. retrievepulls components into your repo.deployuploads a zip with a chosentestLevel(NoTestRun, RunSpecifiedTests, RunLocalTests, RunAllTestsInOrg) and options such ascheckOnly(validation),rollbackOnError.- Salesforce validates dependencies, compiles Apex and runs tests.
- The result lists successes, failures and test coverage.
- Deletions use
destructiveChanges.xml.
Advanced / deep dive: In a pipeline: developers commit to Git, a pull request triggers a validation deploy (checkOnly) with tests to a sandbox or production, and merge triggers a quick deploy of the validated package (within the validation window, verify current number of days) to avoid rerunning tests. Production deployments require 75 percent overall Apex coverage and each class/trigger being covered at least 1 percent; running tests in production deployments depends on testLevel (RunLocalTests is the default for Apex deploys to production). Limits include roughly 10,000 files and about 39 MB for the zip (verify current values), so split large deployments. Not every setting is supported; check the Metadata Coverage Report. Related APIs: (fine-grained, interactive development, debug logs, code coverage) and wrappers.