I want to update the DeveloperName field via Apex in a Custom MetadataType. I would like to replace "VALUE1" with "VALUE2". Instead, however, it just inserts another line. Is it possible to update DeveloperName via Apex at this time (since Delete is not supported as of yet)?

Metadata.CustomMetadata customMetadata =  new Metadata.CustomMetadata();
customMetadata.fullName = 'MySetting__mdt.VALUE2';
customMetadata.label = 'MyLabel';

Metadata.DeployContainer mdContainer = new Metadata.DeployContainer();

Id jobId = Metadata.Operations.enqueueDeployment(mdContainer, null);

enter image description here


This isn't possible. The Apex Metadata API essentially uses the file-based Metadata API under the covers, and it's not possible to use the file-based Metadata API to rename components.

  • Except, I've found you can certainly update other fields using Apex Metadata API. Just haven't figured out if there's a way to update the "DeveloperName" field. Use this: sfdcpanther.com/create-update-custom-metadata-using-apex and this: corevalue.net/deploying-custom-metadata-records-apex-code for reference. – Edwin Schaeffer Oct 17 '19 at 18:33
  • I guess it can't be changed. Unfortunately, "DeveloperName" was the field I was relying on to set Mule environments. Any hopes of writing post deployment scripts to set this field to the correct setting is now gone. I have to flip this to custom settings now and change it in 30 different places. – Edwin Schaeffer Oct 18 '19 at 15:29
  • In general, I really don't recommend using the DeveloperName field for anything but identifying the record. – Avrom Roy-Faderman Oct 18 '19 at 21:28
  • Basically, you can't update that field because, from the perspective of the Apex MD API (or the regular MD API, for that matter), developer name (together with namespace) is used to identify what record you're talking about. If you change the name, it has no way of knowing that you mean the original record. – Avrom Roy-Faderman Oct 18 '19 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.