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?


Why not query InstalledSubscriberPackage using tooling API?

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

SOQL to get Installed Package details


  • So no direct call from Apex available? The downside of the web service call is needing the remote site setting up (as well as more code).
    – Keith C
    May 21 '18 at 19:20
  • Yeah.. except Tooling couldn't find anything in Native Apex. May 21 '18 at 19:51

Unlike the other answers, this query lets you do this directly in Apex using SOQL

Publisher[] publishers = [SELECT Id, DurableId, Name, NamespacePrefix, IsSalesforce, MajorVersion, MinorVersion FROM Publisher]

Note: The patch version number is not stored on this table

New contributor
Harout is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

I know this is very old but I think that using a query like below can help you, and that is using "pure Apex":

PackageLicense[] licensedPackages = [select NamespacePrefix, Status from PackageLicense];

Even better if you know the namespace prefix (e.g. n):

PackageLicense[] licensedPackages = [select Status from PackageLicense where NamespacePrefix = 'n'];

That is only going to show if this was licensed.

  • Thanks but it is the package version number I'm looking for not whether the package is licensed or not.
    – Keith C
    Oct 3 '20 at 11:07
  • Got you, maybe worth considering having a global class on the Managed Package that returns System.requestVersion(). Otherwise Tooling API still the best bet. Oct 3 '20 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.