Sub topic 2
Reading and Setting Package Version Numbers
This chapter assumes Salesforce DX basics, scratch orgs, Apex tests, JSON, Git, and command-line use.
Version numbers
A 2GP version uses four numbers:
major.minor.patch.build
- Major: breaking changes or a major product release.
- Minor: compatible features.
- Patch: compatible fixes.
- Build: a specific build of that major, minor, and patch version.
In sfdx-project.json, use NEXT when Salesforce should choose the next build number:
{
"package": "AcmeApp",
"versionName": "Spring update",
"versionNumber": "1.1.0.NEXT",
"ancestorVersion": "HIGHEST"
}LATEST can select the latest matching dependency version. It is useful during development, but pin exact versions for predictable releases.
Build and test a package version
Create the version from the package source. --code-coverage runs Apex tests and records coverage required for promotion.
sf package version create --package AcmeApp --installation-key-bypass --code-coverage --wait 20 --target-dev-hub devhubInstall the resulting version in a scratch org and test its behavior there:
sf org create scratch --definition-file config/project-scratch-def.json --alias pkg-test --set-default
sf package install --package [email protected] --target-org pkg-test --wait 10
sf apex run test --target-org pkg-test --code-coverage --result-format humanCheck both automated test results and real package behavior. Coverage alone does not prove that configuration, permissions, or upgrades work correctly.
Dependencies and extension packages
Declare a dependency in the package directory entry. The dependent package must be available to the target Dev Hub.
{
"path": "force-app",
"package": "AcmeApp",
"versionNumber": "1.1.0.NEXT",
"ancestorVersion": "HIGHEST",
"dependencies": [
{
"package": "BasePackage",
"versionNumber": "1.2.0.LATEST"
}
]
}An extension package adds features that depend on a base package. Keep each package boundary intentional because subscribers must install compatible dependency versions.
Promote the tested version
A newly created version is usually beta. After validation, promote it:
sf package version promote --package [email protected] --target-dev-hub devhubPromotion makes the version released. Released versions can be installed in production orgs and used for distribution.
Exercise
What does 1.2.3.NEXT request when creating a package version?
Show answer
It requests the next available build for major version 1, minor version 2, and patch version 3.