Newer Version Available

This content describes an older version of this product. View Latest

Extract Dependency Information from Unlocked Packages

For an installed unlocked package, you can now run a simple SOQL query to extract its dependency information. You can also create a script to automate the installation of unlocked packages with dependencies.

The SubscriberPackageVersion Tooling API object now provides dependency information. Using a SOQL query on SubscriberPackageVersion, you can identify the packages on which your unlocked package has a dependency. You can get the (04t) IDs and the correct install order for those packages.

Example

Package B has a dependency on package A. Package D depends on packages B and C. Here’s a sample sfdx-project.json that you would have specified while creating a package version. Package D dependencies are noted as packages A, B, and C.
1{
2    "packageDirectories": [
3        {
4            "path": "pkg-a-workspace",
5            "package": "pkgA",
6            "versionName": "ver 4.9",
7            "versionNumber": "4.9.0.NEXT",
8            "default": true
9        },
10        {
11            "path": "pkg-b-workspace",
12            "package": "pkgB",
13            "versionName": "ver 3.17",
14            "versionNumber": "3.17.0.NEXT",
15            "default": false,
16            "dependencies": [
17                {
18                    "package": "pkgA",
19                    "versionNumber": "3.3.0.LATEST"
20                }
21            ]
22        },
23        {
24            "path": "pkg-c-workspace",
25            "package": "pkgC",
26            "versionName": "ver 2.1",
27            "versionNumber": "2.1.0.NEXT",
28            "default": false
29        },
30        {
31            "path": "pkg-d-workspace",
32            "package": "pkgD",
33            "versionName": "ver 1.1",
34            "versionNumber": "1.1.0.NEXT",
35            "default": false,
36            "dependencies": [
37                {
38                    "package": "pkgA",
39                    "versionNumber": "3.3.0.LATEST"
40                },
41                {
42                    "package": "pkgB",
43                    "versionNumber": "3.12.0.LATEST"
44                },
45                {
46                    "package": "pkgC",
47                    "versionNumber": "2.1.0.LATEST"
48                }
49            ]
50        }
51    ],
52    "namespace": "",
53    "sfdcLoginUrl": "https://login.salesforce.com",
54    "sourceApiVersion": "44.0",
55    "packageAliases": {
56        "pkgA": "0HoB00000008Oq6KAE",
57        "pkgB": "0HoB00000008OqBKAU",
58        "pkgC": "0HoB00000008OqGKAU",
59        "pkgD": "0HoB00000008OqGKAQ"
60    }
61}
Before installing pkgD (with ID=04txx000000082hAAA), use this SOQL query to determine its dependencies. The username is typically the target subscriber org where the unlocked package is to be installed.
1sfdx force:data:soql:query -u {USERNAME} -t 
2   -q "SELECT Dependencies FROM SubscriberPackageVersion 
3       WHERE Id='04txx000000082hAAA'" --json
You see this output when you run the query, with the (04t) IDs for pkgA, pkgB, and pkgC in that order.
1"Dependencies":{"Ids":[
2   {"subscriberPackageVersionId":"04txx000000080vAAA"},
3   {"subscriberPackageVersionId":"04txx000000082XAAQ"},
4   {"subscriberPackageVersionId":"04txx0000000AiGAAU"}]}