Sub topic 6
Reading and setting version numbers
This chapter assumes you have a Dev Hub, a linked namespace, and a package created with sf package create. You should be comfortable editing sfdx-project.json. Here you will learn how a package version number is built, what the NEXT and LATEST keywords do, and how the number affects upgrades.
The four parts of a version number
A second-generation package version number has four parts: major.minor.patch.build. Example: 1.2.0.5.
| Part | Who sets it | Meaning |
|---|---|---|
| major | You | Large releases, such as a new product generation |
| minor | You | Feature releases that add functionality |
| patch | You | Fixes. Patch versions need extra setup, covered in a later chapter |
| build | Salesforce, or you | Distinguishes each build of the same major.minor.patch |
You set the number in the versionNumber field of the package directory entry in sfdx-project.json. The first three parts are plain integers. The fourth is usually the keyword NEXT.
The NEXT and LATEST keywords
Use NEXT in the package's own versionNumber. When you run sf package version create, Salesforce replaces NEXT with the next unused build number for that major.minor.patch. With 1.0.0.NEXT, your first build is 1.0.0.1, the second is 1.0.0.2, and so on.
Use LATEST in a dependency's versionNumber. It points to the newest build of that major.minor.patch of the other package. For example, 1.2.0.LATEST resolves to the highest build of version 1.2.0 at the time you create your version.
{
"path": "force-app",
"default": true,
"package": "AcmeApp",
"versionName": "Spring update",
"versionNumber": "1.1.0.NEXT",
"ancestorVersion": "HIGHEST",
"dependencies": [
{
"package": "BasePackage",
"versionNumber": "1.2.0.LATEST"
}
]
}Each build gets an alias in sfdx-project.json in the form [email protected]. The alias uses a hyphen before the build number. Commands such as sf package version promote and sf package install take this alias.
Version name versus version number
versionName is a label for people, such as "Spring update". It is not unique and does not control ordering. versionNumber is what Salesforce compares. Change versionNumber when you plan a new release, and change versionName to describe it.
Rules that affect your choices
- A released version number cannot be reused. Once
1.0.0.1is promoted, you cannot build and promote another1.0.0build as a release. - For a managed package, you can only promote a version when its minor or patch number differs from the previous released version, or when the major number is higher. Rebuilding the same major.minor.patch and promoting it again fails.
- Version numbers must increase. Raise the minor number for a feature release and the major number for a breaking change in your own process, since Salesforce does not inspect your metadata to enforce semantic meaning.
Common mistakes
- Hard-coding a build number such as
1.1.0.3in your own package. The next create then fails or collides with an existing build. UseNEXT. - Using
NEXTin a dependency. Dependencies needLATESTor a specific build. - Forgetting to raise the minor number after releasing, then trying to promote a second
1.0.0build.
Exercise
Your last released version is 1.0.0.3. You want to start work on a feature release. What should versionNumber be in sfdx-project.json, and what alias will the first build get?
Show answer
Set versionNumber to 1.1.0.NEXT. The first build is 1.1.0.1, so its alias is [email protected].