Sub topic 15
When to Use Other Deployment Tools
This chapter assumes you can already build, upload, validate, and deploy a change set, and that you know what a package.xml manifest is. Here you will learn where change sets stop being the right tool and which tools fit better.
Why change sets are not always enough
Change sets are good at one job: an administrator moves a small, hand-picked group of metadata components from one related org to another using only the Setup UI. They need no extra software and no command line, which is why they remain popular.
The same design causes the limits you met earlier in this tutorial:
- Components must be picked by hand, one type at a time.
- Orgs must share a deployment connection, so you cannot deploy between unrelated orgs.
- There is no version history. A change set records what you uploaded, not how a component changed over time.
- You cannot delete components with a change set.
- Not every metadata type is supported.
- You cannot script or automate the process.
When these limits start costing you time or causing mistakes, look at another tool.
The main alternatives
Salesforce CLI with a manifest
The Salesforce CLI (sf) deploys and retrieves metadata from a terminal. It uses the same package.xml manifest format shown earlier in this tutorial, so the list of components is familiar. The manifest lists members by metadata type, just as a change set does.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Invoice__c</members>
<name>CustomObject</name>
</types>
<types>
<members>InvoiceService</members>
<members>InvoiceServiceTest</members>
<name>ApexClass</name>
</types>
<version>61.0</version>
</Package>You can retrieve those components from a sandbox into local files:
sf project retrieve start --manifest manifest/package.xml --target-org MySandboxOnce the files are on disk, you can deploy them to any org you can log in to. A shared connection between the orgs is not required. You can also deploy to an org that is not related to the source, such as a sandbox from a different production org.
sf project deploy start --manifest manifest/package.xml --target-org MyProduction --test-level RunLocalTestsThe --test-level flag gives you the same choices you saw for change sets, such as NoTestRun, RunLocalTests, and RunAllTestsInOrg. To check a deployment without saving it, use sf project deploy validate and, later, sf project deploy quick with the validated job ID.
Source control with a CI/CD pipeline
When metadata files live in a Git repository, every change has an author, a date, and a diff. A continuous integration and delivery (CI/CD) pipeline is an automated process that runs your checks and deployments whenever someone changes the repository. A typical pipeline does this:
- A developer commits changes to a branch and opens a pull request.
- The pipeline validates the changes against a sandbox or the production org.
- A reviewer approves the pull request and merges it.
- The pipeline deploys the merged changes to the next environment.
The diagram below shows this flow.
This approach gives you reviews, history, repeatable deployments, and rollback by reverting a commit. The cost is setup and maintenance. Your team needs to learn Git and manage credentials for the pipeline securely.
Salesforce DevOps Center
DevOps Center is a Salesforce tool that brings source control and a pipeline into a point-and-click interface. Admins track work as items, and the tool commits the changes to a Git repository and moves them through pipeline stages. It suits teams that want version control without asking every admin to use the command line.
Unlocked packages and managed packages
A package is a versioned container of metadata. Packages suit cases where you install the same functionality in many orgs, or where you want clear ownership and upgrade paths.
- Unlocked packages are for your own organization. They support versions and dependencies between packages.
- Managed packages are for distributing an application to other companies, usually through AppExchange.
Packages need more planning than a change set. Components belong to a package, and you must handle dependencies between packages.
Other options
- Metadata API tools, such as the Ant Migration Tool, are older command-line options. Salesforce now recommends the CLI.
- Third-party DevOps products add features such as release tracking, comparison, and rollback. They usually cost money.
- Data tools, such as Data Loader or the CLI data commands, move records. Change sets and the tools above move metadata, not data.
Comparing the tools
| Tool | Skill needed | Version history | Works between unrelated orgs | Can delete components | Automation |
|---|---|---|---|---|---|
| Change sets | Admin, UI only | No | No | No | No |
| Salesforce CLI | Command line | Only with Git | Yes | Yes, with a destructive manifest | Yes |
| CLI with Git and CI/CD | Command line and Git | Yes | Yes | Yes | Yes |
| DevOps Center | Admin, some Git concepts | Yes | Within its pipeline | Limited | Partly |
| Unlocked packages | Developer | Yes, by package version | Yes | By upgrading the package | Yes |
Check the current Salesforce documentation before you rely on a cell in this table. Product features change between releases.
Decision criteria
Ask these questions in order.
- How often do you deploy, and how many people deploy? A few small changes a month by one admin suit change sets. Frequent releases by several people suit source control.
- Do you need to know who changed what, and to undo it? If yes, you need version history, which means Git.
- Are the orgs related? If a source and target have no deployment connection, change sets are not possible.
- Do you need to delete components or use an unsupported metadata type? Use the CLI with a destructive changes manifest, or another tool.
- Is the same functionality going to many orgs? Consider packages.
- Who will maintain the process? A pipeline that nobody understands is worse than a change set that the whole team can run.
Failure modes when you switch
- Drift between orgs. If some changes go through change sets and others through Git, the repository no longer matches production. Retrieve production metadata before you start, and make the repository your single record from then on.
- Manifest gaps. A manifest that lists too little produces the same missing dependency errors you saw with change sets. The CLI does not offer a "View/Add Dependencies" button, so you must check dependencies yourself or deploy to a sandbox first.
- Test level surprises. Production deployments that include Apex still need the required test coverage, whatever tool you use. Validate first.
- Credential handling. A pipeline needs authorized access to your orgs. Store credentials in the pipeline's secret store, never in the repository.
A suggested migration path
- Pick a sandbox and retrieve a small slice of metadata with a manifest, as shown above.
- Put the files in a Git repository and commit them.
- Deploy the same slice to a second sandbox with the CLI, using
sf project deploy validatefirst. - Compare the result with what a change set would have produced.
- Add a pipeline only after the manual steps are reliable.
Exercise
Your team deploys twice a week, five people edit the same Apex classes, and a recent deployment overwrote a colleague's work with no way to see what changed. Which tool fits better than change sets, and which two features of it address the problem?
Show answer
Source control with the Salesforce CLI and a CI/CD pipeline (or DevOps Center if the team prefers a point-and-click interface). Version history shows who changed what and lets you revert, and pull requests with automated validation let reviewers catch overwrites before they reach production.
Exercise
You must remove an obsolete custom field from production and also deploy to a sandbox that belongs to a different production org. Why can't change sets do either, and what do you use instead?
Show answer
Change sets cannot delete components, and they only work between orgs that have a deployment connection, which unrelated orgs do not have. Use the Salesforce CLI: a destructive changes manifest removes the field, and a CLI deployment can target any org you can authenticate to.