SFDX command to find the latest package version

You can use the tooling API (sfdx force:data:soql:query) to simply query for package versions:

SELECT Id,Package2Id,SubscriberPackageVersionId,Description,IsDeprecated,IsPasswordProtected,IsReleased FROM Package2Version ORDER BY CreatedDate DESC LIMIT 1

This query will return the latest package version, with SubscriberPackageVersionId beeing the 04t Id that you can use to install the package.

You can build any logic to retrieve only Package Versions to specific packages (use Package2Id to filter for that) or only the latest version of a given MajorVersion. You can also use this to extract / solve dependencies.

Resources:

  • Tooling API Documentation: Package2Version
  • SFDX Documentation: Extract Package Dependencies

Tags:

Salesforcedx