Using IsDeprecated to reduce the number of packages returned by force:package:version:list

As you develop your package, the versions start to pile up in Salesforce’s servers. Suddenly you can find yourself getting dozens of results with force:package:version:list in your DevHub org. If the project lasts for years and you are working in a fast-paced environment, you surely will have a bad time with this list.

This command has some attributes to help you filter the package list using the date in which the package was created, the date when the package was modified (both in days), by its release status and you can also order the packages by some fields on the Package2Version object. Just a tip: --orderby Version doesn’t work (because the version field returned on our terminal is actually a representation of all four version fields).

But then what if I just want to list my latest stable released package? This command won’t do. Fortunately for us Salesforce is “API First” so we can query the Package2Version table using the Tooling API to filter the results with a SOQL query.

If we want only the released packages, we include the IsReleased = TRUE.

If we want filter out the deprecated ones, add a IsDeprecated = FALSE then.

We can even get the ones protected by passwords, with the IsPasswordProtected field.

Example query:

$ sfdx force:data:soql:query -t -u DevHub -q "SELECT Id, SubscriberPackageVersionId, IsPasswordProtected FROM Package2Version WHERE Package2.Name = 'MY_AWESOME_PACKAGE_ALIAS' AND IsReleased = TRUE AND IsDeprecated = FALSE"
──────────────────  ──────────────────────────  ───────────────────
05iXX000000XXX0XXX  04tXX00000XXXX0XXX
05iXX000000XXX1XXX  04tXX00000XXXX1XXX          true

This is great, but how can I mark a package version as deprecated again?

The documentation about the Package2Version object lists the fields and says that the update call is supported. Also, the IsDeprecated field description contains this snippet:

If you set IsDeprecated to true for a package, the package and all of its child package versions are deprecated.

Package2Version docs

The “if you set to true” part and the lack of “read-only” in this cell indicate that this field is writable. We can probably update it using the Tooling API and the Salesforce CLI.

I have two released package versions, one of those is not password protected because I forgot to manually assign it the password. I don’t want the installation Id (the one starting with 04t) to fall into wrong hands, because I’m dealing with an Unlocked package here. I don’t want people to see my precious metadata! So I’ll just deprecate that version and people won’t be able to install it anymore:

$ sfdx force:data:record:update -s Package2Version -i 05iXX000000XXXXXXX -v "IsDeprecated=true" -u DevHub -t
Successfully updated record: 05iXX000000XXXXXXX.

Great! Now only me and my password manager know the key to install this package. 😌

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s