Querying installed Managed package version numbers from Apex in 2018

This was asked in 2015 – Querying Managed package version from Apex – (and in other posts here) but I want to check that there has been no change to this in the last 3 years.

We have several managed packages and want to introduce another small managed package (that cannot have compile-time dependency on the others) that contains links to a documentation server. The documentation is versioned there to match the managed package versions, so we would like to automatically discover the current version of all our managed packages. Then the correct links can be offered. An SObject we could query would be ideal…

How can these versions best be found using Apex code with these constraints?

Answer

Why not query InstalledSubscriberPackage using tooling API?

SELECT Id, SubscriberPackageId, SubscriberPackage.NamespacePrefix,
SubscriberPackage.Name, SubscriberPackageVersion.Id,
SubscriberPackageVersion.Name, SubscriberPackageVersion.MajorVersion,
SubscriberPackageVersion.MinorVersion,
SubscriberPackageVersion.PatchVersion,
SubscriberPackageVersion.BuildNumber
FROM InstalledSubscriberPackage
ORDER BY SubscriberPackageId

SOQL to get Installed Package details

Source:https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_installedsubscriberpackage.htm

Attribution
Source : Link , Question Author : Keith C , Answer Author : Pranay Jaiswal

Leave a Comment