6

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?

3 Answers 3

2

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

2
  • 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, 2018 at 19:20
  • Yeah.. except Tooling couldn't find anything in Native Apex. May 21, 2018 at 19:51
0

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

-1

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.

3
  • Thanks but it is the package version number I'm looking for not whether the package is licensed or not.
    – Keith C
    Oct 3, 2020 at 11:07
  • 1
    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, 2020 at 11:17
  • Tricky part of that last comment would be -- it will return package version based on a package version referred in your current class
    – kurunve
    Jul 20 at 9:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .