通过带有标签的Apex在Salesforce中添加选择列表值

时间:2018-07-03 16:27:10

标签: salesforce metadata apex

我想通过Apex添加一些PickListValues。这是我的代码:

MetadataService.MetadataPort service = createService();
MetadataService.CustomField customField = new MetadataService.CustomField();
customField.fullName = 'CustomAddress__c.city2__c';
customField.label = 'Packlast';
customField.type_x = 'Picklist';
customField.description = 'HHHHHH';
metadataservice.Picklist pt = new metadataservice.Picklist();
pt.sorted= false;
metadataservice.PicklistValue two = new metadataservice.PicklistValue();
two.fullName= 'MyAPI';
two.default_x=true ;

metadataservice.PicklistValue three = new metadataservice.PicklistValue();
three.fullName= 'Klostein';
three.default_x=false ;
pt.picklistValues = new list<metadataservice.PicklistValue>{two,three};
customField.picklist = pt ;

List<MetadataService.SaveResult> results =
service.updateMetadata(
new MetadataService.Metadata[] { customField });
handleSaveResults(results[0]);

这很好。但是我需要将Label和API Name写入值中。所以我试图在field_order_type_info的类PicklistValue中添加字符串标签:

private String[] field_order_type_info = new String[ 
 {'label','color','fullName','default_x','description','isActive', 'allowEmail','closed','controllingFieldValues','converted','cssExposed','forecastCategory','highPriority','probability','reverseRole','reviewed','won'};

但是我收到例外

System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: Element {http://soap.sforce.com/2006/04/metadata}label invalid at this location in type PicklistValue faultcode=soapenv:Client faultactor=

0 个答案:

没有答案