'我正在尝试通过 Apex 更新销售人员元数据记录。这是我的代码:
Metadata.DeployContainer mdContainer = new Metadata.DeployContainer();
for(Omni_Routing_Skillset__mdt md: omnimetadata) {
Metadata.CustomMetadata customMetadata = new Metadata.CustomMetadata();
customMetadata.fullName = md.DeveloperName; //custom metadata name
customMetadata.Label = md.MasterLabel;
Metadata.CustomMetadataValue customField1 = new Metadata.CustomMetadataValue(); //the values you're changing/updating
customField1.field = 'Omni_Routing_Skillset__mdt.Skill_Level__c'; //the custom field API Name that you're wanting to insert/update a value of
customField1.value = skillsAndValues.get(md.MasterLabel);
customMetadata.values.add(customField1);//add the changes to list of changes to be deployed
mdContainer.addMetadata(customMetadata);
System.debug('customMetadata: ' + customMetadata);
}
//MetadataDeploy callback = new MetadataDeploy();
Id jobId = Metadata.Operations.enqueueDeployment(mdContainer, null);
这将开始部署,但我收到以下错误:
**Must specify the name in the CustomMetadataType.CustomMetadata format, Current Name: Team_2_SEP, Required Delimiter: .**
我不知道如何解决这个问题,有人可以建议吗?
谢谢!
名称为 Omni_Routing_Skillset__mdt.Team_2_SEP,您仅在 Team_2_SEP 中传递。
可以参考这个方法:
public static void updateExisitingMetadatRecord() {
List<Metadata_Creditional__mdt> metadatList = [SELECT Id, DeveloperName,
MasterLabel FROM Metadata_Creditional__mdt WHERE DeveloperName='MyTest'];
Metadata.CustomMetadata metadataRec = new Metadata.CustomMetadata();
metadataRec.fullName =
'Metadata_Creditional__mdt.'+metadatList[0].DeveloperName;
metadataRec.label = metadatList[0].MasterLabel;
//provide the value for the fields and add it to custom metadata instance
Metadata.CustomMetadataValue totalPurchasetoUpdate = new
Metadata.CustomMetadataValue();
totalPurchasetoUpdate.field = 'Secret_Key__c';
totalPurchasetoUpdate.value = 'Change Secreet Value';
metadataRec.values.add(totalPurchasetoUpdate);
Metadata.DeployContainer mdContainer = new Metadata.DeployContainer();
mdContainer.addMetadata(metadataRec);
Metadata.Operations.enqueueDeployment(mdContainer, null);
}
customMetadata 全名应该是对象的名称(不带 __mdt)+ '.' + 您记录的开发者名称:
customMetadata.fullName = 'IntegrationSettings.main';
customMetadata 标签应该是您记录的主标签:
customMetadata.label = 'main';
这些字段是通常的 __c 字段名称(不带对象名称):
Metadata.CustomMetadataValue theField = new Metadata.CustomMetadataValue();
theField.field = 'AccessToken__c';
theField.value = '123';