Sub topic 15
Pushing upgrades and shipping patches
This chapter assumes you can build, promote and install a package version, and that you have set ancestors, as covered in the earlier chapters. Here you will see how a released version reaches subscribers without each admin installing it, and how to ship a small fix without a new minor release.
Two ways a subscriber gets a new version
A subscriber is an org that has installed your package. There are two ways it moves to a newer version:
- Pull upgrade. An admin installs the newer version from an install link or with
sf package install. The subscriber chooses the timing. - Push upgrade. You schedule the upgrade from the Dev Hub. Salesforce installs the version in the subscriber org without an admin acting.
A push upgrade replaces an admin's install step, so it needs the same safety rules as any upgrade. The platform only allows upgrades that follow your ancestry chain and the managed-package rules. Because no admin reviews a push upgrade, you must test it more carefully than a version you only publish.
What a push upgrade needs
Check these conditions before you schedule one:
- The target version must be released. A beta version cannot be pushed, because beta versions are only installable in scratch orgs, sandboxes and Dev Hub-related test orgs.
- The target must be a valid upgrade for the version the subscriber has now. In practice it must come later in the same ancestry line. You cannot push a version to an org that has a version your target does not descend from.
- You schedule the push from the Dev Hub that owns the package, using a user with permission to manage packages there.
- The list of subscriber orgs comes from you. You can find installed orgs through the License Management App or the Dev Hub's package subscriber data, and then choose which ones to include.
Pushes are tracked in two kinds of records in the Dev Hub. A push request describes the target version and the start time. A push job records the result for each individual subscriber org. This lets you see which orgs succeeded, which failed, and why.
The Salesforce CLI exposes push upgrades through the sf package push-upgrade command group. Its flags have changed between CLI releases, so run sf package push-upgrade schedule --help to see the exact options your installed version supports. The command takes a package version ID (starting with 04t), a start time, and a list of target orgs.
Choosing a rollout strategy
Pushing to every subscriber at once is rarely the best choice. A safer pattern is to roll out in waves:
- Push to your own sandboxes and a few friendly customers.
- Check the push jobs for failures and read the error messages.
- Push to a larger group.
- Push to everyone else.
A failed push job usually means the subscriber org has a conflict. Common causes are a custom field or validation rule that interacts badly with your changes, or an Apex test failure in the subscriber's own code that runs during installation. Fix these by correcting the package or by contacting the subscriber. You cannot force the upgrade through.
The table below summarizes when each delivery method fits.
| Situation | Better choice |
|---|---|
| Security or data-loss bug | Push upgrade, in waves |
| Small fix to Apex logic | Patch version, push or pull |
| New feature with setup steps for admins | Pull upgrade, with release notes |
| Change that alters admin-visible behavior | Pull upgrade, with notice |
A silent change to behavior that admins rely on can cause support cases. Push the changes that are invisible to users, and let admins choose when to take the others.
Patch versions
The version number has four parts: major.minor.patch.build. A patch version has a non-zero patch number, for example 1.1.1. It exists to deliver a bug fix to subscribers who are on a specific minor release, without moving them to features from the next one.
To build a patch version you do three things in sfdx-project.json:
- Keep the major and minor numbers of the version you are fixing.
- Raise the patch number above zero.
- Set the ancestor to the released version you are patching.
{
"packageDirectories": [
{
"path": "force-app",
"default": true,
"package": "AcmeApp",
"versionName": "Patch 1.1.1",
"versionNumber": "1.1.1.NEXT",
"ancestorVersion": "1.1.0"
}
],
"namespace": "acme",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "61.0"
}Use an explicit ancestor here. The HIGHEST keyword from the earlier chapter picks the highest released version, which may be a newer minor release than the one you are patching.
Build the patch from a branch that holds the code of version 1.1.0 plus your fix, not from your main branch. The main branch likely contains work for 1.2.0, and you do not want unfinished features in a patch. A good habit is to create a branch from the Git tag you made when you promoted 1.1.0.
git checkout -b patch/1.1.1 v1.1.0
# apply the fix, then commit it
sf package version create --package AcmeApp --installation-key-bypass --code-coverage --wait 20 --target-dev-hub devhubAfter the build succeeds, test the upgrade path, promote the version, and deliver it.
sf package version promote --package [email protected] --target-dev-hub devhubLimits on patches
A patch is meant for fixes, so the platform limits what it may change. You should expect restrictions on changes that affect the package's public contract, such as removing global Apex or changing a published interface. Those rules also apply to any release of a managed package. The exact list of what a patch may add or change is documented by Salesforce and has changed over time, so check the current packaging guide if your fix touches anything beyond Apex bodies, labels or similar internals.
Keep these gotchas in mind:
- A patch needs its own build and promotion. Promoting
1.1.0does not promote1.1.1. - Patch numbers do not replace minor numbers. If a fix needs new components or new behavior, release it as
1.2.0. - Any version you promote is permanent. You can deprecate a released version so that new installs are blocked, but you cannot edit or delete it.
Testing the upgrade before you ship it
A version that installs cleanly into an empty org can still fail as an upgrade. Always test the upgrade itself:
- Create a scratch org or sandbox.
- Install the version your subscribers have now, for example
[email protected]. - Add realistic data and configuration, such as records, page layout edits and permission set assignments.
- Install the new version over it.
- Check that data and configuration survived and that the app behaves correctly.
sf package install --package [email protected] --target-org upgrade-test --wait 10
sf package install --package [email protected] --target-org upgrade-test --wait 10Run your Apex tests after the second install. This catches problems such as a changed default value or a record type that subscribers had customized.
Practical checklist
- Tag every released version in Git so you can branch patches from it.
- Keep release notes for every patch, even when you push it silently.
- Roll out pushes in waves and read the failed jobs before you widen the audience.
- Use explicit ancestors for patches.
- Keep a record of which orgs are on which version, so you know who still needs a fix.
Exercise
Your released version 2.3.0 has a bug in an Apex class. Your main branch already holds unfinished work for 2.4.0. Describe how you would ship the fix as a patch, and name the values you would set in sfdx-project.json.
Show answer
Create a branch from the Git tag of 2.3.0, apply and commit only the fix, and set versionNumber to "2.3.1.NEXT" and ancestorVersion to "2.3.0". Build the version with sf package version create, test an upgrade from 2.3.0 in a scratch org or sandbox, promote 2.3.1 to released, and then either let admins install it or schedule a push upgrade in waves.
Exercise
Why can't you push upgrade a beta package version to subscribers?
Show answer
Only released versions can be pushed. Beta versions are for testing in scratch orgs and sandboxes, and you must promote a version to released before it can reach production subscriber orgs.