Sub topic 11
Installing a version in sandboxes and production
This chapter assumes you can already build a package version with sf package version create and know the difference between beta and released versions. It covers how to install a version into a target org, which orgs accept which versions, and the errors you are most likely to hit.
Beta and released versions decide where you can install
Installability depends on the version's state, not on a flag you set at install time.
| Version state | Scratch orgs | Sandboxes | Production |
|---|---|---|---|
| Beta | Yes | Yes | No |
| Released | Yes | Yes | Yes |
Install every version in a sandbox first. Promote it only after the install and your tests succeed there, because a released version can never be changed or deleted in a way that affects subscribers.
Install with the CLI
The install command takes a package alias with a version, or a subscriber package version ID that starts with 04t.
sf package install --package [email protected] --target-org my-sandbox --wait 10The alias [email protected] was added to sfdx-project.json when the version was created. The --wait 10 option makes the command wait up to 10 minutes and report the final result. Without it, the command returns immediately and the install continues in the background. You can then check it with sf package install report.
If you set an installation key when you built the version, pass it with --installation-key. The earlier build used --installation-key-bypass, so no key is needed here.
Install in production
Production accepts only released versions. Use the same command with the production org as the target.
sf package install --package [email protected] --target-org my-production --wait 10A subscriber can also install from a link. Every version has an install URL of this form, where the 04t ID is the subscriber package version ID:
https://login.salesforce.com/packaging/installPackage.apexp?p0=04tXXXXXXXXXXXXXXXUse test.salesforce.com instead of login.salesforce.com for sandboxes.
What happens during an install
Common errors
- Version is beta and the target is production. Promote the version with
sf package version promote, then retry. - Missing dependency. The target org needs every package listed in
dependencies, at a compatible version. Install the dependency first, or list it in the--packagechain of an install script. - Wrong alias. The alias is case sensitive and must match an entry under
packageAliases. Checksfdx-project.jsonif the CLI says it cannot find the package. - Org not authorized.
--target-orgmust name an org you logged in to withsf org login web.
Exercise
You built version 1.0.0-1 and have not promoted it. Can you install it in a sandbox? In production? What should you do before the production install?
Show answer
You can install it in a sandbox because beta versions are allowed there, but not in production. Test it in the sandbox, then run sf package version promote --package [email protected] to release it, and then install it in production.