Sub topic 11
Promoting a beta version to released
This chapter assumes you can create a package version, read sfdx-project.json, and install a package into a scratch org. It covers what separates a beta version from a released one and how to promote a version.
Beta and released versions
Every package version you create starts as a beta. A beta version can be installed in scratch orgs, sandboxes and Developer Edition orgs, but not in production. A beta is also mutable in one sense: the version number 1.0.0.NEXT resolves to a new build number each time, so you can keep building until the content is right.
Promoting a version sets its status to released. Once it is released:
- You can install it in production.
- You can no longer change its metadata. To fix something, you build a new version.
- Any later version must have a higher major, minor or patch number than the released one. Build numbers alone do not count as a new release.
Promotion does not rebuild anything. It flags an existing version, so the metadata you tested is the metadata you ship.
Requirements for promotion
A version can be promoted only if:
- It was created with code coverage calculated (
--code-coverage) and the Apex tests reached at least 75% coverage. - You have access to the Dev Hub that owns the package.
- It is not already released.
If you skipped --code-coverage when building, you must build a new version. Coverage cannot be added afterwards.
The promotion flow
Promoting and installing
Promote by package alias and version, then install the same alias in the target org:
sf package version promote --package "[email protected]" --target-dev-hub MyDevHub
sf package install --package "[email protected]" --target-org MyProdOrg --wait 20The CLI asks for confirmation before promoting, because the action cannot be undone. In a pipeline, add --no-prompt to skip the question.
To check the status of your versions, list them:
sf package version list --packages Core --target-dev-hub MyDevHubThe output includes a Released column. Use it to confirm that production installs point at a released version.
Common errors
- Installing a beta in production. The install fails because the version is not released. Promote it first.
- Promoting without coverage. The command fails with a coverage error. Rebuild with
--code-coverageand fix any gaps in your tests. - Promoting the wrong build. The alias
[email protected]and[email protected]are different versions. Check the alias insfdx-project.jsonunderpackageAliasesbefore you promote. - Expecting to edit a released version. Released versions are immutable. Build the next version number instead.
Exercise
Exercise
You built [email protected] without the --code-coverage flag. Tests would pass at 90%. Can you promote it, and what should you do?
Show answer
No. Promotion requires that coverage was calculated when the version was built, and you cannot add it later. Build a new version with sf package version create --package Core --code-coverage --installation-key-bypass --wait 20, confirm it reaches at least 75%, then promote the new version.
Exercise
Why can't you edit the metadata of a released version, and what do you do when you find a bug in one?
Show answer
Released versions are immutable so that every org that installs a given version gets identical content. To fix the bug, change the source, build a new version with a higher major, minor or patch number, promote it, and install it as an upgrade.