0

What I have done : Installed repository from GIT HUB In my Personal org https://githubsfdeploy.herokuapp.com/app/githubdeploy/financialforcedev/apex-mdapi

Created a custom controller and method : Inside method getting

Variable does not exist: picklist

in this line

customField.picklist.picklistValues.add(newPicklistvalue);

Apex method:

private void addPicklistValue(MetadataService.CustomField customField, string picklistValue) {

    MetadataService.MetadataPort service = createService();

    metadataservice.PicklistValue newPicklistvalue = new metadataservice.PicklistValue();
    newPicklistvalue.fullName= picklistValue;
    newPicklistvalue.default_x = false;



    customField.picklist.picklistValues.add(newPicklistvalue);

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

    refreshFields(customField);
}

Why do I get this error? How can I fix it?

2

You are trying to access a property of the CustomField Metadata API entity, picklist, that is deprecated and unavailable in current API versions. From the linked Metadata API reference for CustomField:

picklist: (Deprecated. Use this field in API version 37.0 and earlier only. In later versions, use valueSet instead.)

For this reason, you will not find it in current versions of apex-mdapi. Presumably you're working from sample code or examples that are out of date.

As is common when working with the Metadata API, you'll have to do some legwork to understand the complex data structures that are in use. The ValueSet type and its nested ValueSetValuesDefinition type are documented in the Metadata Field Types documentation.

In the apex-mdapi library, you'll find the definition of the ValueSet class inside MetadataService.cls.

That's what you'll need to use to make your updates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.