Sub topic 3
Installing and Releasing a 2GP Package
Assume you know Salesforce orgs, scratch orgs, Apex tests, Git, and the Salesforce CLI. A package version must be promoted before production installation. Test beta versions in sandboxes or scratch orgs first.
Install and upgrade safely
Install a released version in a target org with its package alias:
sf package install --package [email protected] --target-org my-sandbox --wait 10A package upgrade works only when Salesforce can connect the new version to the installed version. Set ancestorVersion to the previous released version, or use HIGHEST to select the highest released ancestor. This preserves upgrade paths and prevents incompatible metadata changes.
{
"versionNumber": "1.1.0.NEXT",
"ancestorVersion": "HIGHEST"
}Managed packages protect subscriber organizations. Subscribers cannot directly edit protected package components, and upgrades must respect metadata and data compatibility. Plan destructive changes carefully because an upgrade does not automatically remove every component.
AppExchange and licensing
After testing, promote the beta version:
sf package version promote --package [email protected] --target-dev-hub devhubA production AppExchange listing normally requires Salesforce security review. The review checks application behavior and security practices. After approval, publish the listing and manage customer access with the License Management App (LMA). The LMA records package licenses and subscriber organizations, which helps track usage and renewals.
Push upgrades and patches
Push upgrades let a publisher deliver an approved package upgrade to selected subscriber orgs without asking each administrator to start the installation. Use them for planned releases and communicate timing clearly. Patch versions fix a released version while preserving its major, minor, and patch line. They are narrower than feature releases and still require testing.
Automate and migrate
A CI pipeline can authenticate to the Dev Hub, create a package version with code coverage, wait for validation, and install it in a test org. Store authentication secrets in the CI provider, not in Git.
A 1GP package migration requires planning its namespace, metadata, version ancestry, and subscriber upgrade path. Confirm Salesforce migration eligibility before attempting the conversion. Do not treat migration as a new unrelated package if existing subscribers must upgrade.
Exercise
Why should a package version declare an ancestor?
Show answer
The ancestor connects it to an earlier release so Salesforce can calculate a compatible upgrade path.