4

By using CustomMetadata class we can update or create custom metadata type records as below,

Metadata.CustomMetadata customMetadata =  new Metadata.CustomMetadata();
customMetadata.fullName = 'ISVNamespace__MetadataTypeName.MetadataRecordName';

Metadata.CustomMetadataValue customField = new Metadata.CustomMetadataValue();
customField.field = 'customField__c';
customField.value = 'New value';
customMetadata.values.add(customField);

Metadata.DeployContainer mdContainer = new Metadata.DeployContainer();
mdContainer.addMetadata(customMetadata);
...
Id jobId = Metadata.Operations.enqueueDeployment(mdContainer, callback);

But, How can we delete custom metadata record?

1

1 Answer 1

3

As Salesforce documentation says, this is not currently possible. You can just Read, Create and Update records.

Apex code can create, read, and update (but not delete) custom metadata records, as long as the metadata is subscriber-controlled and visible from within the code's namespace.

You must log in to answer this question.

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