0

I am doing automation on package installation after refreshing sandbox Found and follow this one https://github.com/litify/apex-mdapi/blob/55d755fc0c7e8d519dc10a5a3fa21aa0d7bda17b/apex-mdapi/src/classes/MetadataServiceExamples.cls#L616

findAndInstallLatestPackage() {
    if (packageVersionNumber != null) {
            // Install the package in the current org using the latest version number

            MetadataService.InstalledPackage installedPackage = new MetadataService.InstalledPackage();
            installedPackage.versionNumber = packageVersionNumber;
            installedPackage.password = '....'; //
            installedPackage.fullName = 'MANAERP'; // namespace

            List<MetadataService.UpsertResult> results =
                service.upsertMetadata(
                    new MetadataService.Metadata[] { installedPackage });

            handleUpsertResults(results[0]);

        } else {
            System.debug('No package versions found or unable to determine the latest version.');
        }
}

for doing test I hardcode packageVersionNumber to specific number Then I tried to open Developer Console and run

PackageInstaller a = new PackageInstaller();
a.findAndInstallLatestPackage();

But I got error

PackageInstaller.MetadataServiceExamplesException: Error occured processing component MANAERP. InstalledPackage namespace: manaerp does not exist! (PACKAGING_API_INSTALL_FAILED).

enter image description here

Im just wondering if can the root cause is the difference between PBO and developer org, The package version was created on PBO org. in that time, we're trying to install in another org?

2

1 Answer 1

1

The Metadata API’s InstalledPackage entity can only be used to install 1GPs. To install a 2GP programmatically, use the Tooling API’s PacageInstallRequest.

0

You must log in to answer this question.

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