I am attempting to remove some custom metadata, I am able to deploy it, and view a successful result, but when I create a new Metadata.DeployContainer container
, and use the container.removeMetadata
or container.removeMetadataByFullname
method the data remains (and is not marked as deleted in deployment result callback)?
List<String> dpmFullnames = new List<String>{'MyMetaDataName.lasZ', 'MyMetaDataName.zNkrh', 'MyMetaDataName.zNkA'};
List<String> dpmDontRemove = new List<String>{'lasZ'};
System.debug(dpmFullNames);
Metadata.DeployContainer container = new Metadata.DeployContainer();
List<Metadata.Metadata> savedCustomMetadata =
Metadata.Operations.retrieve(Metadata.MetadataType.CustomMetadata,
dpmFullnames);
for(Metadata.Metadata dpm : savedCustomMetadata){
Metadata.CustomMetadata dpmRecord = (Metadata.CustomMetadata) dpm;
String recordName = dpmRecord.fullName.substringAfter('.');
if(!dpmDontRemove.contains(recordName)){
System.debug('Remove '+recordName);
container.removeMetadataByFullname('MyMetaDataName.'+recordName);
} else {
System.debug('Add '+recordName);
container.addMetadata(dpmRecord);
}
}
SonarCustomMetaDataDeployCallback callback = new SonarCustomMetaDataDeployCallback();
Id asyncResultId = Metadata.Operations.enqueueDeployment(container, callback);
If I remove all the data, I get an error that I can not deploy an empty container. Assuming it is just removing them, not setting them as "deleted"?