1

I know that I can use Metadata API and can use Apex to run Metadata API to delete metadata, like Custom Metadata records.

I know that I can leverage Metadata.Operations class to create or update Custom Metadata records.

What I struggle is to delete protected custom metadata record which was created by Metadata.Operations class from the managed package, since when I try to run this, I receive an error "No custom metadata named found". I tried to add namespace prefix and remove namespace prefix, but it doesn't work. Is there any workarounds or options for this?

The problem is that if we create protected custom metadata record in subscriber org and unable to delete it and refer to some custom field on subscriber org, then the subscriber will not be able to delete that custom field unless completely uninstalling our package, which is not the action we want to suggest to the customer.

I understand the problem is that Metadata API cannot access the protected metadata record from the package to delete that record.

Is there any elegant solution to this problem?

5
  • The Apex would have to be part of the managed package namespace to be able to do this. You could ask the package developer if they have a means to delete it, or whether they would delete it for you via subscriber access (where you grant them access to the org for "support").
    – Phil W
    Apr 12, 2022 at 19:55
  • Yes, my apex is the part of the managed package namespace, I am the package developer.
    – Patlatus
    Apr 12, 2022 at 20:03
  • @PhilW also looks like even using LMA subscriber success org support, it is not possible to delete the protected custom metadata records salesforce.stackexchange.com/questions/277727/…
    – Patlatus
    Apr 12, 2022 at 20:07
  • Is your package 1GP or 2GP?
    – Phil W
    Apr 12, 2022 at 21:12
  • 2GP, but it really doesn't matter
    – Patlatus
    Apr 13, 2022 at 8:31

1 Answer 1

0

Looks like there is no available option to delete the protected custom metadata records.

The only viable workarounds here are:

  1. Make the custom metadata records public.
  2. Use protected list custom settings instead of custom metadata records.
  3. We can use text fields instead of object and field references to allow customers to delete their referenced fields and objects. We can use Active checkbox on custom metadata records and set it to false instead of deleting the custom metadata record.
  4. Also we can change the object and field references to be no longer required and clear their value when deactivating the record.

You must log in to answer this question.

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