Sub topic 10
Promoting a Version to Released
This chapter assumes you can already build a package version with sf package version create, read a major.minor.patch.build version number, and work with sfdx-project.json. It covers what promotion does, what it locks in, and the errors you will hit most often.
What promotion changes
Every second-generation managed package (2GP) version starts as a beta version. A beta version is a working build that you can install in scratch orgs, sandboxes, and Developer Edition orgs. You cannot install it in a production org, and you cannot list it on AppExchange.
Promotion changes a version's status from beta to released. A released version can be installed in production orgs and distributed to customers. Promotion does not rebuild anything. The same package version ID (starting with 04t) stays the same, and only its status flag changes.
| Property | Beta | Released |
|---|---|---|
| Install in scratch orgs and sandboxes | Yes | Yes |
| Install in production orgs | No | Yes |
| Eligible for AppExchange listing | No | Yes |
| Can be deleted | Yes | No |
| Can be an ancestor of later versions | No | Yes |
| Metadata can be freely changed in later versions | Yes | Restricted by managed-package rules |
The last two rows matter most. Once a version is released, you cannot delete it, and it becomes part of the history that subscribers depend on.
What you need before you promote
The CLI refuses to promote a version that has not met these conditions:
- The version was created with code coverage calculated (
--code-coverageonsf package version create). - Apex code coverage is at least 75 percent across the package.
- The version was created successfully, so its status is
Success. - The version number is unique among released versions with the same major, minor, and patch numbers.
- You have permission to promote versions in the Dev Hub org.
A version built with --skip-validation is a special case. It is faster to build because it skips dependency and metadata validation, but you cannot promote it. Use it only for quick development builds.
Check the state of your versions before you promote:
sf package version list --packages AcmeApp --target-dev-hub devhubThe output shows the version number, subscriber package version ID, status, code coverage, and whether the version is released. Look for your candidate version and confirm that coverage is above 75 percent.
You can also inspect a single version in detail:
sf package version report --package [email protected] --target-dev-hub devhubRunning the promotion
Use the package alias that sfdx-project.json created when you built the version:
sf package version promote --package [email protected] --target-dev-hub devhubThe CLI asks you to confirm, because the action cannot be undone. In a script, add --no-prompt to skip the confirmation:
sf package version promote --package [email protected] --no-prompt --target-dev-hub devhubYou can pass either the alias ([email protected]) or the 04t ID directly. After promotion, sf package version list --released shows the version.
The promotion workflow
A safe release follows a fixed order. You build, test, and only then promote.
Notice that a failed check sends you back to a new build, not to editing the existing version. Package versions are immutable. Once a version is built, its contents never change.
Which version should you promote?
Beta versions with the same major.minor.patch differ only in the build number. For example, 1.0.0.1, 1.0.0.2, and 1.0.0.3 are three separate builds of what you intend to call 1.0.0. Only one of them can be released.
The rule is this: for a given major.minor.patch, you can promote one build, and after that, you cannot promote any other build with the same three numbers. If you promoted 1.0.0.2, builds 1.0.0.1 and 1.0.0.3 stay beta forever. The next release needs a higher major, minor, or patch number, such as 1.1.0.NEXT.
This is why the common error below happens.
Common errors
| Symptom | Cause | Fix |
|---|---|---|
| Promotion fails because coverage is insufficient | The version was built without `--code-coverage`, or coverage is below 75 percent | Add tests, then create a new version with `--code-coverage` |
| Promotion fails because the version was built with `--skip-validation` | Validation was skipped at build time | Build again without `--skip-validation` |
| Promotion fails because a version with that number is already released | Another build with the same major, minor, and patch was promoted | Increase the minor or patch number in `sfdx-project.json` and build again |
| Production install fails with a beta version | The version is still beta | Promote it, then install |
| Promotion fails on a dependent package | A dependency is itself still beta | Promote the dependency first |
The last row is easy to miss. If AcmeApp depends on BasePackage, then BasePackage must be released before AcmeApp can be. Promote packages in dependency order, from the base upward.
Interaction with ancestry
Promotion is also the point where ancestry becomes meaningful. In the previous setup, "ancestorVersion": "HIGHEST" means the next build names the highest released version as its ancestor. If you have never promoted anything, there is no highest released version, and you should use "ancestorVersion": "NONE" for the first release, as the first version of the package does.
Only a released version can serve as an ancestor. That is why a beta build cannot be used as the base for a subscriber upgrade path. A later chapter covers ancestry and upgrade compatibility in full. For now, keep this in mind: the order in which you promote versions shapes the upgrade path that your subscribers follow.
After you promote 1.0.0.1, a typical next entry in sfdx-project.json looks like this:
{
"path": "force-app",
"default": true,
"package": "AcmeApp",
"versionName": "Spring update",
"versionNumber": "1.1.0.NEXT",
"ancestorVersion": "HIGHEST"
}Verifying a released version
After you promote, confirm the result before you tell anyone it is ready.
- List released versions and find yours:
``bash sf package version list --packages AcmeApp --released --target-dev-hub devhub ``
- Install it in a sandbox. Since the version is now released, the install uses the same command as before:
``bash sf package install --package [email protected] --target-org my-sandbox --wait 10 ``
- Check that the package appears under Installed Packages in Setup and that its components behave as expected.
Production installs use the same command with the production org as the target. Some teams give customers the installation URL instead, which has the form https://login.salesforce.com/packaging/installPackage.apexp?p0=04t.... Replace login.salesforce.com with test.salesforce.com for sandboxes.
Habits that prevent trouble
- Promote from a clean tag. Record the Git commit of the version you promoted so you can reproduce the source later.
- Promote after testing the version that you built, not a similar one. Beta builds are cheap, so test the exact
04tID. - Keep a short release note that links the version number to its
04tID. - Treat promotion as a gate in your CI pipeline, with a manual approval step before it runs.
Exercise
Your team built AcmeApp versions 2.0.0.1, 2.0.0.2, and 2.0.0.3. You promoted 2.0.0.2. A teammate then finds a typo in a label and wants to promote 2.0.0.3, which contains the fix. What happens, and what should you do?
Show answer
The promotion of 2.0.0.3 fails, because only one build per major.minor.patch can be released and 2.0.0.2 already holds that slot. Released versions also cannot be changed or deleted. Fix the typo in source, raise the version number in sfdx-project.json (for example to 2.0.1.NEXT), build a new version with --code-coverage, test it, and promote that build.
Exercise
You run sf package version promote on a version you built with --skip-validation, and it fails. Name the reason and the fix.
Show answer
Versions built with --skip-validation cannot be promoted, because dependency and metadata validation never ran. Create the version again without --skip-validation and with --code-coverage, then promote the new build.