Sub topic 5
Beta versus released versions and promotion
This chapter assumes you know how to read a MAJOR.MINOR.PATCH.BUILD version number, can edit sfdx-project.json, and can create a package version with the sf CLI. It covers the two states a package version can be in, what each state allows, and how promotion moves a version from one to the other.
Two states of a package version
Every package version you create is either beta or released.
- A beta version is a work in progress. You can install it only in scratch orgs, sandboxes, and Developer Edition orgs. You cannot install it in production.
- A released version is fixed and supported. You can install it in any org, including production.
A new version always starts as beta. The only way to change its state is to promote it. Promotion is one-way, so a released version can never go back to beta.
| Property | Beta | Released |
|---|---|---|
| Installable in production | No | Yes |
| Can be a dependency of a released version | No | Yes |
| Can be deleted | Yes | Only if it was never installed in production (unlocked packages) |
| Can be the base for an upgrade path | No | Yes |
| Can be promoted | Yes | Already done |
The exact deletion rules differ by package type. Check the current Salesforce documentation for the package type you use.
How the build number fits in
Versions that share the same MAJOR.MINOR.PATCH but differ in BUILD are separate versions. You can build 1.1.0.1, 1.1.0.2, and 1.1.0.3 as betas. Salesforce allows only one released version for each MAJOR.MINOR.PATCH combination, so you promote exactly one of them. The others stay beta and cannot be promoted later.
The beta-to-released flow
Promoting a version
Use sf package version promote. The command takes the package version alias or its 04t ID.
sf package version create --package Utils --installation-key-bypass --wait 20 --code-coverage --target-dev-hub myDevHub
sf package version promote --package "[email protected]" --target-dev-hub myDevHubThe CLI asks you to confirm, because the action cannot be undone. In scripts, add --no-prompt to skip the confirmation.
After promotion, sf package version list --released --target-dev-hub myDevHub shows the version. Without the --released flag, the list includes both states.
What promotion requires
Salesforce checks these conditions when you promote an unlocked package version.
- Code coverage. You must have created the version with
--code-coverage, and the Apex code in the package must meet at least 75% coverage. A version created with--skip-validationcannot be promoted, because it skipped the checks that promotion depends on. - Released dependencies. Every package your version depends on must itself be released. A beta dependency blocks promotion.
Managed packages follow similar rules, and they also need to pass any security review requirements you have for distribution.
Why the distinction matters for dependencies
Suppose Sales App depends on Utils. You can build and install a beta of Sales App in a scratch org while its dependency on Utils points to a beta of Utils. To release Sales App, you must first release the Utils version it depends on. This sets the release order. Promote dependencies first, then the packages that use them.
Dependencies using the LATEST keyword resolve to the newest build, which might be a beta. This is useful during development. Before you promote, check which version LATEST resolved to, and consider pinning the dependency to a released version.
Common mistakes
- Trying to install a beta version in production. The install fails. Promote it first.
- Promoting a build that was created without code coverage. Create a new version with
--code-coverage. - Promoting a dependent package before its dependency. Promote the dependency first.
- Expecting to promote an older build after a different build of the same MAJOR.MINOR.PATCH was released. Create a new version with a higher number.
Exercise
You created Utils versions 1.1.0-1, 1.1.0-2, and 1.1.0-3, all as betas. You promote 1.1.0-2. A teammate then asks you to promote 1.1.0-3 as well because it has a small fix. What happens, and what should you do?
Show answer
The promotion of 1.1.0-3 fails, because only one version for each MAJOR.MINOR.PATCH can be released, and 1.1.0-2 already holds that place. Put the fix in a new version with a higher number, for example 1.1.1.NEXT or 1.2.0.NEXT, create it with --code-coverage, test it, and promote that version.
Exercise
Sales App 2.0.0-1 depends on the beta Utils 1.1.0-1. You run the promote command for Sales App 2.0.0-1. Why does it fail, and what is the correct order of steps?
Show answer
A package with a beta dependency cannot be promoted. First promote Utils 1.1.0-1 so that it is released, then promote Sales App 2.0.0-1. If the Utils build is not the one you want to release, create a new Sales App version that points to the released Utils version.