Sub topic 10
Installing a Package Version into an Org
This chapter assumes you can already build a package version with sf package version create and that you have a Dev Hub, a scratch org, and the Salesforce CLI authorised against them. Here you install a version and handle the usual installation errors.
What installation does
Installing a package version deploys all of its metadata into a target org as one unit. Salesforce records the package and version in that org. The org can then upgrade the package later, and the package's components are tracked as members of it.
You identify a version either by its alias, such as [email protected], or by its subscriber package version ID, which starts with 04t. The alias works only when it appears in the packageAliases section of sfdx-project.json. The 04t ID works anywhere, including in orgs that have no copy of your project.
Install commands
Install into a scratch org or sandbox using the alias:
sf package install --package "[email protected]" --target-org MyScratch --wait 20 --no-promptInstall by ID into any org, with an installation key if the version has one:
sf package install --package 04tXXXXXXXXXXXXXXX --target-org MyProdOrg --installation-key "myKey123" --wait 20The --wait flag is the number of minutes the CLI waits for the install to finish. Without it, the command returns immediately and you must check progress with sf package install report.
Beta and released versions
A version you have just built is a beta. You can install a beta only in scratch orgs, sandboxes, and developer edition orgs. Production accepts only released versions, so you must promote the version first. Promotion is covered in the next chapter.
Installing in the right order
When Sales depends on Core, Core must be in the org before Sales. If you install Sales by its 04t ID and Core is missing, the install fails. The CLI can install dependencies for you, but only when you use sf package install for each package in order, or when you build the version with the dependency declared in sfdx-project.json. In scripts, install the lowest-level package first.
sf package install --package "[email protected]" --target-org MyScratch --wait 20 --no-prompt
sf package install --package "[email protected]" --target-org MyScratch --wait 20 --no-promptCommon errors
| Symptom | Likely cause | Fix |
|---|---|---|
| "Cannot install beta package" in production | The version is not promoted | Run `sf package version promote` |
| "Invalid installation key" | Key missing or wrong | Pass `--installation-key` |
| Dependency not found | Required package or version is absent | Install the dependency first |
| Install times out | `--wait` too low for a large package | Raise `--wait`, then run `sf package install report` |
Checking what is installed
List the packages in an org to confirm the result:
sf package installed list --target-org MyScratchThe output shows each package name, version number, and subscriber package version ID.
Exercise
You built [email protected] and try to install it into production, but the install fails. Name two possible causes and the fix for each.
Show answer
First, the version is still a beta, so promote it with sf package version promote and install again. Second, the dependency Core is not installed in production, so install the released Core version first, then Sales.