Sub topic 11
Promoting a Beta Version to Released
This chapter assumes you can already create a package and build a package version with the Salesforce CLI. It also assumes you know what Apex code coverage is and how a Dev Hub tracks packages. Here you will learn what "beta" and "released" mean, what promotion does, and what goes wrong when you promote.
Beta and released: two states of a version
Every package version you build starts as a beta version. A beta version is a candidate. You can install it in scratch orgs, sandboxes, and Developer Edition orgs to test it. You can't install it in production.
A released version is a version you have marked as ready for production. Promotion is the step that changes the state from beta to released. The command is sf package version promote.
Promotion changes only the state of the version record in the Dev Hub. It does not rebuild the version, change its metadata, or install anything. The version keeps the same ID and the same contents.
Why the two states exist
The two states separate "this build might be good" from "this build is approved." A team can create many beta versions per day while it develops. Only a few of them should ever reach production.
The states also protect the version number. Beta versions can be deleted. A released version can't be deleted, and its number can't be reused. Production orgs may depend on a released version, so the platform keeps it stable.
| Property | Beta version | Released version |
|---|---|---|
| Install in production | No | Yes |
| Install in scratch org or sandbox | Yes | Yes |
| Can be deleted | Yes | No |
| Can be used as a dependency of a released version | No | Yes |
| Upgrade path from earlier versions | Not supported | Supported |
Requirements before you can promote
Promotion fails unless the version meets several conditions.
- The version was built with code coverage. Create it with
--code-coverage. A version built without it can't be promoted. - Coverage is at least 75%. The Apex code in the package must meet this minimum overall. The version create step calculates and stores the value.
- The build succeeded. A version whose creation failed has no usable record to promote.
- The version is still beta. Promoting a released version returns an error.
- You have permission in the Dev Hub. Your user needs access to create and update package versions.
Skip coverage only when you need a quick test build. The CLI offers --skip-validation on sf package version create. A version built that way can be installed in a scratch org for testing, but it can't be promoted. Treat it as throwaway.
Dependencies matter too. Suppose Sales depends on Core. If you want to promote Sales, the Core version it depends on must already be released. Promote Core first, then Sales.
Promoting with the CLI
Use the package alias or the version ID (a 04t ID). The alias form is easier to read in scripts.
sf package version promote --package "[email protected]" --target-dev-hub MyDevHubThe CLI asks you to confirm. It warns that the action is permanent for that version. In automation, add --no-prompt to skip the confirmation.
sf package version promote --package "[email protected]" --no-prompt --target-dev-hub MyDevHubYou can check the result with the version list.
sf package version list --packages Core --target-dev-hub MyDevHubThe output includes an IsReleased column. After a successful promotion it shows true for that version.
To see the details of one version, including coverage, use the report command.
sf package version report --package "[email protected]" --target-dev-hub MyDevHubThe role of the NEXT keyword
During development, the version number in sfdx-project.json is 1.0.0.NEXT. Each build replaces NEXT with the next build number, which gives 1.0.0-1, 1.0.0-2, and so on. The alias in packageAliases for each build looks like [email protected].
Promotion locks in one of these builds. Once 1.0.0-3 is released, you can't release 1.0.0-4 with the same major, minor and patch numbers. The platform requires a higher major.minor.patch for every new released version. Before your next release, change the version in sfdx-project.json to 1.1.0.NEXT (or another higher value), then build again.
A common sequence:
- Build
1.0.0-1,1.0.0-2,1.0.0-3as betas while you work. - Promote
1.0.0-3. - Change the project file to
1.1.0.NEXT. - Build
1.1.0-1and continue.
Installing after promotion
Once released, install the version into production by alias or ID.
sf package install --package "[email protected]" --target-org MyProdOrg --wait 20Install dependencies before the packages that need them. Installing a released Sales version into an org that has no compatible Core version fails. If you install through the CLI with an alias, the CLI can resolve and install the dependencies for you in the correct order when the dependencies are listed in the project file. Check the output to confirm which versions were installed.
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Promotion fails with a message that coverage is missing | The version was built without `--code-coverage` or with `--skip-validation` | Build a new version with `--code-coverage` and promote that one |
| Promotion fails with a coverage percentage below the minimum | Apex coverage is under 75% | Add tests, rebuild, and promote the new version |
| Production install fails with a message that the version is beta | The version has not been promoted | Promote it, then install again |
| Promotion fails because a dependency is not released | The dependent Core version is still beta | Promote Core first |
| Cannot create a new version with the same number | A released version already uses that major.minor.patch | Increase the version number in `sfdx-project.json` |
| Cannot find the version | Wrong alias, or the alias is missing from `packageAliases` | Run `sf package version list` and use the exact alias or `04t` ID |
Gotchas
Promotion is permanent. If you promote the wrong build, you can't undo it. You can deprecate the released version, and you can publish a fixed one with a higher number. Deprecation does not remove the version from orgs where it is already installed.
Test the exact build you promote. Do not test 1.0.0-2 and then promote 1.0.0-3 because it "looks the same." Each build is a different artifact, and metadata or dependency changes can slip in between builds.
Promote from your pipeline, not a laptop. Having a single place that runs the promote command makes it easier to see who released what and when.
Exercises
Exercise
You built [email protected] with --skip-validation and tested it in a scratch org. Can you promote it? What should you do?
Show answer
No. A version built with --skip-validation has no code coverage calculation, so it can't be promoted. Rebuild the version with --code-coverage, test that new build, and promote it once coverage is at least 75%.
Exercise
Sales depends on [email protected]. Core 1.0.0-5 is a beta. You try to promote the Sales version built against it, and the command fails. What is the correct order of steps?
Show answer
Promote the Core version first, then build Sales against the released Core version if needed, test it, and promote Sales. A version can't be released while it depends on a beta version.
Exercise
You released [email protected] and now want to ship a bug fix. What must you change before building the next version, and why?
Show answer
Increase the version number in sfdx-project.json, for example to 1.0.1.NEXT or 1.1.0.NEXT. The platform won't let you build another released version with the same major.minor.patch as an already released one.