Sub topic 3
Installing a Package Version into an Org
Assume you know Salesforce orgs, metadata, Apex, Salesforce DX projects, and the sf CLI. A package version is a specific, installable snapshot of package contents.
Install in dependency order
Install the required package version into the target org:
sf package install --package "[email protected]" --target-org myOrg --wait 10The package alias must resolve to a subscriber package version ID, such as an 04t... ID. Use the exact version when repeatable deployments matter.
If Sales App depends on Utils, install Utils first unless your release process already installs and verifies dependencies:
flowchart TD
U[Install Utils 1.1.0-1] --> A[Install Sales App 2.0.0-1]
A --> T[Run tests and verify metadata]caption: Dependency installation order alt: A flowchart showing Utils installed before Sales App, followed by tests
Ancestry and upgrades
Ancestry records the version line from which a package version was created. For managed packages, released versions normally need a valid ancestry relationship to support upgrades. You cannot freely upgrade one unrelated package line into another.
An upgrade can add or change supported package contents, but package rules still apply:
- Managed package subscribers cannot modify protected package components.
- A package version cannot remove or change an API contract without considering existing subscribers.
- Unlocked package upgrades depend on matching package identity and compatible contents.
- Test an upgrade path, not only a fresh installation.
Version references and Apex behavior
A component’s -meta.xml file can record the managed package version it used:
<packageVersions>
<majorNumber>1</majorNumber>
<minorNumber>0</minorNumber>
<namespace>acme</namespace>
</packageVersions>Managed-package Apex can inspect the caller’s requested package version with System.requestVersion(). This allows older callers to keep older behavior while newer callers use new behavior.
Org-dependent unlocked packages
An org-dependent unlocked package declares that some metadata or features already exist in the target org. This can reduce packaging constraints, but it transfers responsibility to deployment setup. Prepare the org first, and document the required metadata.
Troubleshooting
- Dependency not found: install the required package version first.
- Version conflict: replace
LATESTwith a compatible exact version. - Invalid ancestry: create the version from the correct package lineage.
- Missing metadata: deploy prerequisite metadata or configure the org-dependent package correctly.
- Installation timeout: increase
--waitand inspect the installation request in the org.
Exercise
Sales App requires Utils version 1.1.0-1. Which package should you install first?
Show answer
Install Utils 1.1.0-1 first, verify it succeeds, and then install Sales App.