Sub topic 7
Version numbers and the NEXT keyword
Every unlocked package version has a four-part number, and the Salesforce CLI fills in one of those parts for you. This chapter covers what each part means, what NEXT does, and how version numbers interact with promotion and dependencies. It assumes you can read an sfdx-project.json file, that you have already created a package with sf package create, and that you know a package version is an immutable, installable snapshot of the metadata in a package directory.
The four-part version number
A package version number has the form major.minor.patch.build. In sfdx-project.json it appears in the versionNumber field of a package directory.
| Part | Who sets it | Typical meaning |
|---|---|---|
| major | You | Large or breaking changes, such as removing or restructuring components |
| minor | You | New features that remain compatible |
| patch | You | Small fixes |
| build | The platform, when you use `NEXT` | A counter for each version created from the same major.minor.patch |
Salesforce does not enforce semantic versioning. The platform only checks ordering and uniqueness, so the meaning of each part is a team convention. Agree on it early. A common rule is that a major bump signals a change consumers must plan for, such as a removed global component or a changed dependency.
What NEXT does
In sfdx-project.json, you normally write the build part as the literal word NEXT:
{
"packageDirectories": [
{
"path": "force-app/core",
"package": "Core",
"versionName": "Spring release",
"versionDescription": "Adds account scoring fields",
"versionNumber": "1.1.0.NEXT",
"default": true
}
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "61.0"
}When you run sf package version create, the Dev Hub replaces NEXT with the next unused build number for that major.minor.patch. The first version created for 1.1.0 gets build 1, the next gets 2, and so on. When you change the major, minor or patch part, the counter for the new combination starts again at 1.
The Dev Hub assigns the build number, not your project file. The file keeps saying 1.1.0.NEXT, and the result of each build is recorded in packageAliases:
{
"packageAliases": {
"Core": "0Ho000000000001AAA",
"[email protected]": "04t000000000001AAA",
"[email protected]": "04t000000000002AAA"
}
}The IDs above are illustrative. In the alias [email protected], the part after the hyphen is the build number. The 04t ID is the real identifier of the package version, and it is what the platform uses when you install.
Two practical consequences follow:
- Parallel builds from different branches or pipeline runs never collide, because the Dev Hub hands out build numbers.
- You never edit the build number by hand to "bump" a version. Doing so is a common source of confusion and is rarely needed.
Creating versions: a walkthrough
Assume Core is at 1.0.0.NEXT and you have already created several builds. To see what exists, list the versions:
sf package version list --packages Core --target-dev-hub MyDevHubTo build another version of the same major.minor.patch, run the create command with no version flag. The NEXT in the file does the work:
sf package version create --package Core --installation-key-bypass --code-coverage --wait 20 --target-dev-hub MyDevHubTo start the next feature release, change the file to 1.1.0.NEXT and run the same command. You can also override the number from the command line without editing the file:
sf package version create --package Core --version-number 1.1.0.NEXT --installation-key-bypass --code-coverage --wait 20 --target-dev-hub MyDevHubPassing --version-number is useful in a pipeline that computes the number from a release branch or tag. The file and the flag must agree if you want others reading the repository to understand what was built, so prefer editing the file in the same commit as the change.
How version numbers move through a lifecycle
Every build starts as a beta. Only one build of each major.minor.patch can become released. Once you promote it, that major.minor.patch is used up.
After you promote 1.1.0-3, you cannot create or promote another 1.1.0 build. Further changes need a higher number, such as 1.1.1.NEXT or 1.2.0.NEXT. Builds 1.1.0-1 and 1.1.0-2 stay betas. They cannot be installed in production, and you can delete them if you want to tidy the list.
Dependencies and the LATEST keyword
NEXT has a counterpart for dependencies: LATEST. In a dependency entry, LATEST means "the highest build of this major.minor.patch":
{
"package": "Sales",
"versionNumber": "1.0.0.NEXT",
"path": "force-app/sales",
"dependencies": [
{ "package": "Core", "versionNumber": "1.0.0.LATEST" }
]
}Each keyword belongs in a specific place:
NEXTgoes in the package's ownversionNumber, and it means "assign a new build number".LATESTgoes in a dependency'sversionNumber, and it means "resolve to the newest existing build".- Neither keyword can replace the major, minor or patch parts.
You can also pin a dependency to an exact build by using the alias, such as "package": "[email protected]", but then versionNumber is not needed. A pinned dependency is repeatable, because the same build is used every time. A LATEST dependency is convenient, because new builds are picked up automatically. The cost is that two builds of Sales made a week apart can resolve to different builds of Core.
A version you plan to promote needs its dependencies to be released versions. If Sales depends on a beta build of Core, you can still create a beta of Sales for testing, but you cannot promote it until Core is released.
Common errors
- Reusing a released number. Creating a version after promotion with the same major.minor.patch fails. Increase the minor or patch part in
sfdx-project.jsonfirst. - Typing a fixed build number such as
1.0.0.3. Version creation then tries to use that exact build, which fails or conflicts when it already exists. UseNEXTunless you have a strong reason not to. - Expecting the file to change.
versionNumberstays1.0.0.NEXT. Look atpackageAliasesor atsf package version listto see the real build number. - Forgetting that every alias refers to one build.
[email protected]and[email protected]are different04tIDs with different contents. - Changing only the version name.
versionNameandversionDescriptionare labels. They do not make a version unique, and the number alone decides ordering. - Dependency drift. With
LATEST, a rebuild ofSalesmay silently pick up a newerCore. If you need reproducible builds, pin the alias.
Choosing a numbering policy
A small policy avoids most arguments:
- Increase the patch number for fixes that need no changes by consumers.
- Increase the minor number when you add features, or when a new dependency version is required.
- Increase the major number when a change could break installed subscribers or dependent packages.
- Always use
NEXTfor the build number, and let CI create versions rather than developers' laptops, so build numbers stay in order with the pipeline.
Exercise
Your project file says "versionNumber": "2.0.0.NEXT". You have created builds 1 to 4 of 2.0.0, and you promoted build 4. A bug is found. What number must the fix use, and what happens to the NEXT already in the file?
Show answer
The fix cannot use 2.0.0 because that major.minor.patch is released and closed. Change the file to 2.0.1.NEXT (or a higher minor or major number). The Dev Hub then assigns build 1 for 2.0.1 on the first create, giving the alias [email protected]. NEXT stays in the file and always means "the next unused build for this major.minor.patch".
Exercise
Sales has the dependency { "package": "Core", "versionNumber": "1.0.0.LATEST" }. Two Sales builds made a week apart behave differently even though no Sales code changed. What likely happened, and how can you prevent it?
Show answer
A new build of Core 1.0.0 was created between the two Sales builds, and LATEST resolved to the newer Core build. To prevent it, pin the dependency to an exact build by using its alias, such as [email protected], so each Sales build uses the same Core build.