Sub topic 12
Setting ancestors so subscribers can upgrade
This chapter assumes you can already create and promote a package version, and that you know the major.minor.patch.build format. Here you learn how ancestry decides which versions a subscriber can upgrade to.
What an ancestor is
An ancestor is the released package version that a new version builds on. Each version points to one ancestor, so the versions form a chain. Salesforce uses this chain to check that an upgrade is safe for subscribers who already have your package installed.
A subscriber can upgrade to a version only if their installed version is in that version's ancestry. Managed packages also can't remove certain components, such as global Apex classes and methods. The ancestor tells Salesforce which earlier version to compare against when it enforces those rules.
Setting the ancestor in sfdx-project.json
You set the ancestor in the package directory entry with ancestorVersion (or ancestorId).
{
"path": "force-app",
"default": true,
"package": "AcmeApp",
"versionName": "Spring update",
"versionNumber": "1.1.0.NEXT",
"ancestorVersion": "HIGHEST"
}| Value | Meaning |
|---|---|
| `NONE` | No ancestor. Use it for the first version of a package. |
| `HIGHEST` | The highest released version. This is the usual choice for later versions. |
| `ancestorId` | A specific released version, given as an alias or a `04t` ID. |
Only released versions can be ancestors. If you set HIGHEST before you have promoted any version, the build has no ancestor to use.
How ancestry forms a tree
If every new version uses HIGHEST, ancestry is a straight line. You can instead point a new version at an older released version. Then the history branches, which is how you ship a patch for an old release.
A subscriber on 1.0.0 can upgrade to any of the three later versions. A subscriber on 1.0.1 can't upgrade to 1.1.0, because 1.0.1 is not in that version's ancestry.
Common errors
- Setting
ancestorVersiontoNONEon a later version. The CLI checks that your ancestor is the highest released version, so this fails. Passing--skip-ancestor-checkbypasses the check, but only do that on purpose, for example when you are deliberately starting a new branch. - Pointing at a beta version. Promote it first, or choose a released one.
- Forgetting to update the ancestor after a release. When
1.1.0is released, the next minor version should useHIGHEST, which now resolves to it. - Giving a new version a lower number than its ancestor. A version number must be greater than its ancestor's.
Checking the result
After a build, you can inspect a version and see its ancestor:
sf package version report --package [email protected] --target-dev-hub devhubLook at the ancestor fields in the output. If they show the version you expected, subscribers on that version can upgrade.
Exercise
Your highest released version is 1.2.0. You are building 1.3.0 and want every subscriber on 1.2.0 to be able to upgrade. What do you put in ancestorVersion, and why can't you use a beta version as the ancestor?
Show answer
Use HIGHEST, which resolves to the released 1.2.0, or set ancestorId to that version's alias or 04t ID. A beta version can't be an ancestor because only released versions can be, and subscribers install only released versions, so ancestry has to be built from released ones.