4

Is there a way to get version number using SOQL, The below once retrieves only NamespacePrefix, how do i get current version installed..?

SELECT AllowedLicenses,CreatedDate,ExpirationDate,Id,IsProvisioned,LastModifiedDate,NamespacePrefix,Status,SystemModstamp,UsedLicenses FROM PackageLicense
2
  • You can't do this in SOQL. There are ways to get this data, but we need to know what you're trying to do, since the solution would depend on your intent.
    – sfdcfox
    Jul 26, 2017 at 14:30
  • I'm using jsforce plugin on nodejs.
    – Chandu
    Jul 27, 2017 at 5:02

4 Answers 4

1

To build on the jsForce response. This can also be done via the tooling API: https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_installedsubscriberpackage.htm

conn.tooling.sobject('InstalledSubscriberPackage').find({ },[
  "SubscriberPackage.NamespacePrefix",
  "SubscriberPackageVersion.MajorVersion",
  "SubscriberPackageVersion.MinorVersion",
  "SubscriberPackageVersion.PatchVersion"
])
.execute((err, records) =>{
  if (err) { console.error(err); }
  records.forEach((el) =>{
    console.log(
      el.SubscriberPackage.NamespacePrefix
      + " v" +
      el.SubscriberPackageVersion.MajorVersion
      + "." +
      el.SubscriberPackageVersion.MinorVersion
      + "." +
      el.SubscriberPackageVersion.PatchVersion
    );
  });
}
6

Contrary to some answers, you can use SOQL to retrieve this information. You just can't use it in Apex.

In the developer console, if you check the "Use Tooling API" option, the following query will return the information you want:

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

The Salesforce CLI (sfdx) makes it very easy to get a list of installed packages and their version ids:

sfdx force:package:installed:list

Output:

{
  "status": 0,
  "result": [
    {
      "Id": "0A33A000000QgeWSAS",
      "SubscriberPackageId": "0331C00000083VFQAY",
      "SubscriberPackageName": "lwc-json-view",
      "SubscriberPackageNamespace": null,
      "SubscriberPackageVersionId": "04t1C000000goKJQAY",
      "SubscriberPackageVersionName": "ver 0.2",
      "SubscriberPackageVersionNumber": "0.2.0.1"
    }, //... other packages
  ]
}

3

Not doable via sOQL. Using JSForce, you can do a Metadata Retrieve requesting the following members

conn.metadata.retrieve({ apiVersion: '39.0', singlePackage: true, unpackaged: { types: [{ 'members': ['*'], 'name': 'InstalledPackage' }] } })

The response would return all installed packages and and an attribute for their versionNumber

1
  • Note that this returns multiple instances of the same InstalledPackage if it has been installed multiple times with different versions
    – altius_rup
    Sep 6, 2023 at 17:39

You must log in to answer this question.

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