1

I'm using metadataAPi (apex-mdapi)

My current use case is to read the metadata of a custom picklist field, and be returned with the complete list of picklist values available. Regardless of whether the field uses a GlobalValueSet or not. All of the examples on MetadataService are using the deprecated picklistValues code, whereas today we would need to use valueSet.

Currently, I need to return a list of picklistValues (they're a global value set) related to a custom field. The service has been instantiated and everything has been deployed using the github loader.

The code I believe should work is

 MetadataService.CustomField customField = (MetadataService.CustomField) service.readMetadata(
'CustomField', new String[] {'Opportunity.Area_of_Work2_Taxonomy__c' }
).getRecords()[0];

List<MetadataService.CustomValue > pickVals = new List<MetadataService.CustomValue >();
for (MetadataService.CustomValue  pk : customField.valueSet.valueSetDefinition.value ) {
   //pickVals.add(pk);
  System.debug('CS: Individual PK ' + pk );
 }

However, when outputting this information. A null item is returned for customField.valueSet.valueSetDefinition and customField.valueSet.valueSettings System debug of customField.valueSet

ValueSet:[apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false),
controllingField=null,
controllingField_type_info=(controllingField, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false),
field_order_type_info=(controllingField, restricted, valueSetDefinition, valueSetName, valueSettings),
restricted=true,
restricted_type_info=(restricted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false),
valueSetDefinition=null, //HERE
valueSetDefinition_type_info=(valueSetDefinition, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), 
valueSetName=Pitch_category,
valueSetName_type_info=(valueSetName, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false),
valueSettings=null, //HERE
valueSettings_type_info=(valueSettings, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false)]

My assumption is that, according to the Metadata documentation one of those fields should be populated. Is that correct?

Could anyone give me some assistance in either solving or gaining a better understanding of why?

Thank you kindly

1 Answer 1

1

For anyone with a similar problem in the future. I solved this problem by using the valueSetName=Pitch_category, attribute into a second call as a GlobalValueSet

globalPickListApi = (MetadataService.GlobalValueSet) service.readMetadata('GlobalValueSet', new String[] { picklistFieldMdApi.valueSet.valueSetName }).getRecords()[0];

You must log in to answer this question.

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