Sub topic 3
Promoting Unlocked Package Versions
Assume you know Salesforce DX, scratch orgs, Apex tests, and basic metadata deployment. An unlocked package is a versioned unit of Salesforce metadata that your team can install and upgrade.
Promote a beta version
A newly created package version is usually beta. Use beta versions for testing in scratch orgs, sandboxes, or other non-production environments. After validation and required test coverage, promote the version to released:
sf package version promote --package "[email protected]" --target-dev-hub MyDevHub
sf package install --package "[email protected]" --target-org MyProdOrg --wait 20A released version cannot be changed. Create another version when the metadata changes.
Dependencies between packages
Declare dependencies when one package requires metadata from another package. In this example, Sales depends on Core:
{
"packageDirectories": [
{
"path": "force-app/core",
"package": "Core",
"versionNumber": "1.0.0.NEXT",
"default": true
},
{
"path": "force-app/sales",
"package": "Sales",
"versionNumber": "1.0.0.NEXT",
"dependencies": [
{ "package": "Core", "versionNumber": "1.0.0.LATEST" }
]
}
]
}Install Core before Sales. Pin a specific dependency when repeatable builds matter more than automatically receiving the latest compatible version.
Namespaces and package lifecycle
A namespace gives package components globally unique names. Managed packages normally use namespaces to protect components and support controlled distribution. A no-namespace unlocked package is often simpler for one organisation because its components use ordinary names.
Unlocked packages support upgrades by installing a newer version. Deprecate versions that should no longer be selected. Uninstalling removes package metadata when no other metadata depends on it, but review dependencies and data retention before removal.
Org-dependent packages
An org-dependent unlocked package can reference metadata that is not packaged. This can help during migration, but it weakens portability. Use it temporarily or when the target org deliberately supplies the missing metadata.
Migration and CI/CD
Move existing metadata incrementally. Start with a cohesive business capability, test it in a scratch org, and resolve references before adding the next capability. Keep package directories and sfdx-project.json in Git.
A CI/CD pipeline can create a beta version, run tests and code coverage checks, install it in a validation org, and promote it only after approval. Production installation should use the promoted version identifier, not a moving LATEST reference.
Exercise
Why should a Sales package depend on a released Core version rather than an untested beta?
Show answer
A released dependency has passed validation and provides a stable contract for installing and upgrading Sales.