I'm facing with following error:

Developer script exception from Org_Name : 'prefix.AnyClassName' :
Access to entity 'prefix__Some_Metadata__mdt' denied: 
Entity is not api accessible

I have a trigger inside my package which runs @future method.

When I install the package even in fresh org and insert a custom object with trigger I'm getting metadata is not accessible error.

My org is absolutely fresh. Documentation says that I can manipulate with Protected Custom Metadata Type from Apex if they both are inside the package.

I tested future method to just show Custom Metadata Type in some Apex_Log__c record and it fails as well. Is future method use Metadata API in that case and we need to set Visibility of CMT to more permissive?

Are future methods using Metadat

trigger CustomTrigger on CustomObject__c (after insert, after update) {
    //future method called from trigger handler
    // Error failing here:
    // "Access to entity 'prefix__Access_Token__mdt' denied: Entity is not api accessible"
    public static void makeApiCall() {
        //3. retrieves package custom metadata to get token and make API calls
        prefix__Access_Token__mdt accessMDT = [SELECT Id, Refresh_Token__c, Access_Token__c FROM prefix__Access_Token__mdt LIMIT 1];

        //Use token here
        //simpliest situation - fails here as well
        insert new Apex_Log__c(Log_Data__c = accessMDT.Access_Token__c);

  • 3
    Please edit the question to include the code that is trying to update the custom metadata type record(s). A protected custom metadata type record can certainly be manipulated by packaged Apex (in the same package), though you must use the Metadata API.
    – Phil W
    Feb 20, 2023 at 16:12
  • @PhilW I've added some pseudocode Feb 20, 2023 at 22:43
  • You need to show how you do the CMT records update.
    – Phil W
    Feb 20, 2023 at 22:54
  • @PhilW In future method I just retrieve it. For other purposes in other parts of the code I'm updating it by implementing Metadata.DeployCallback before and it updates fine Feb 20, 2023 at 23:01
  • The specific code could be why you get this error, so it is important to show it here.
    – Phil W
    Feb 21, 2023 at 7:04


You must log in to answer this question.

Browse other questions tagged .