Query for Package Ids installed on an org?

I’m in the process of pushing my production org’s metadata into a scratch org. For the most part, the migration is very simple but the biggest gotcha is getting around appexchange dependencies. Any flexipage or report could easily be reference fields or components from an existing app exchange app and cause a number of deployment issues to the scratch org.

SFDX has a nice feature that allows you to install packages from the with sfdx force:package:install -i 04t... -u myScratchOrg

However, tracking down the package Id is very tedious. My current technique is to go to the appExchange, search for the app (which is now a newer version), click the install link and copy the Id from the URL.

Additionally, I could end up installing a dependency that does not match up to my production instance or find that the latest version of the package isn’t backward compatible.

Is there an easier way to find these older package Ids? Such as the tooling API or SOQL query?

Answer

Just run the following command:

sfdx force:package:installed:list -u <alias|username>

This will give you all of the packages installed, including the 04t “AllPackageVersion” Id that you need to install an app.

Sample output:

=== Installed Package Versions [4]
ID                  PACKAGE ID          PACKAGE NAME                           NAMESPACE    PACKAGE VERSION ID  VERSION NAME  VERSION
──────────────────  ──────────────────  ─────────────────────────────────────  ───────────  ──────────────────  ────────────  ────────
0A341000000PiVGCA0  03330000000wDAbAAM  Salesforce Connected Apps              sf_com_apps  04t30000001DUvrAAG  Winter '16    1.7.0.1
0A3410000007m6CCAQ  03341000000GPjnAAG  Opportunity Management Workflow Rules               04t41000002FoDoAAK  January 2017  1.0.0.1
0A341000000eZqxCAE  03341000000TWaHAAW  Trailhead Playground                   th_con_app   04t41000001MvrkAAC  1.10          1.10.0.1
0A341000000nRDtCAM  033B00000000XvZIAU  DreamHouse                                          04tB00000009UeXIAU  Summer 2017   2.0.0.1

Note that this command, for some reason, requires a project directory, so if you need one, use sfdx force:project:create -n <name> beforehand.

Attribution
Source : Link , Question Author : Matthew Mitchener , Answer Author : sfdcfox

Leave a Comment