[SalesForce] Beta Package (Not allowed to install metadata via apex)

I have a beta-managed-package the when deployed has a Apex Metadata API call out that allows users to modify some Custom Metadata that is shipped via the the code. It also allows them to create new Custom Metadata Entries.

This works fine in scratch orgs, and our packaging org, however, we discovered when we installed the beta-package in another developer or scratch org that the Metadata was not deploying after we called:

Metadata.Operations.enqueueDeployment(container, callback);

I captured the exception in a custom field and it says:

Not allowed to install metadata via apex.

I am only installing for Admins, whom have Modify all data permissions, and all the fields on the Custom Metadata type are subscriber editable?

Any ideas?

Best Answer

Never mind, I found it: https://developer.salesforce.com/docs/atlas.en-us.packagingGuide.meta/packagingGuide/packaging_metadata_in_apex.htm,

Specifically:

Managed packages not approved by Salesforce can’t access metadata in the subscriber org, unless the subscriber org enables the Allow metadata deploy by Apex from non-certified Apex package version org preference. Use this org preference when doing test or beta releases of your managed packages.

And in Deploy Metadata from Non-Certified Package Versions via Apex - what does it mean, which outlines where to find the applicable org preference.

Related Topic