Sub topic 2
Beta Versus Released Package Versions
Assume you understand Salesforce DX projects, Dev Hubs, scratch orgs, JSON, and basic sf CLI commands. This chapter focuses on how package versions become installable dependencies.
Beta versus released versions
A beta version is a testable package version. You can install it in a development or test org, but Salesforce does not treat it as a stable release. A released version is a stable version that other packages and production orgs can depend on.
Create a version, test it, and then promote it:
sf package create --name "Utils" --package-type Unlocked --path util --no-namespace --target-dev-hub myDevHub
sf package version create --package Utils --installation-key-bypass --wait 20 --code-coverage --target-dev-hub myDevHub
sf package version promote --package "[email protected]" --target-dev-hub myDevHub
sf package install --package "[email protected]" --target-org myOrg --wait 10Promotion changes the package version from beta to released. Test before promoting because promotion is intended to be permanent.
Declaring a package dependency
A package can declare another package in its sfdx-project.json. Salesforce builds or installs the dependency before the package that uses it.
{
"packageDirectories": [
{
"path": "util",
"package": "Utils",
"versionNumber": "1.1.0.NEXT",
"default": false
},
{
"path": "app",
"package": "Sales App",
"versionNumber": "2.0.0.NEXT",
"default": true,
"dependencies": [
{
"package": "Utils",
"versionNumber": "1.1.0.LATEST"
}
]
}
]
}The package name must match a package alias or package defined in the project. The dependency must be available in the Dev Hub or installation target.
Pinning or floating a version
1.1.0.LATEST floats the build number. Salesforce selects the latest matching build for version 1.1.0. This is convenient for development, but a new build can change what a later package version resolves to.
To pin one exact version, use a package version alias:
{
"dependencies": [
{
"package": "[email protected]"
}
],
"packageAliases": {
"[email protected]": "04t000000000001AAA"
}
}Pin versions for repeatable release builds. Use LATEST when your development process deliberately tracks new builds.
Metadata, features, and org settings
Some dependencies are not packages. A package may require a Salesforce feature or an org setting before installation. Declare those requirements in the package directory, for example with features and orgSettings. These declarations tell Salesforce what the target org must support; they do not install arbitrary metadata for you.
Exercise
Why should a production dependency normally use a pinned released version instead of 1.1.0.LATEST?
Show answer
A pinned released version makes the build repeatable and avoids silently selecting a different dependency build later.