I'm updating picklist value using metadata api and apex. Below is my code snippet and I'm receiving an error:
Variable does not exists: picklist
on:
customField.picklist = pt ;
Can someone help me?
List<MetadataService.SaveResult> results =
service.updateMetadata(
new MetadataService.Metadata[] { customField });
MetadataService.MetadataPort service = createService();
MetadataService.CustomField customField = new MetadataService.CustomField();
customField.fullName = 'Lead.picklist__c';
customField.label = 'picklist';
customField.type_x = 'Picklist';
metadataservice.Picklist pt = new metadataservice.Picklist();
pt.sorted= false;
metadataservice.PicklistValue two = new metadataservice.PicklistValue();
two.fullName= 'second';
two.default_x=false ;
metadataservice.PicklistValue three = new metadataservice.PicklistValue();
three.fullName= 'third';
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 });
Best Answer
The field
picklist
on the CustomField object is deprecated. You will have to use thevalueSet
field instead.Here is how the updated code would look like
I also had to make one more change to the
MetadataService.cls
as per this answer which is to replacewith