I have update dependent picklist inculde,exclude values using metadatapi apex class.how to resolve the above error

// Prepare the picklist with Controlling pickList field 
      MetadataService.Picklist pt = new MetadataService.Picklist();  
      pt.sorted = true;  
      pt.picklistValues = new list < MetadataService.PicklistValue > (); 

      pt.controllingField = controllingFld; 

      // mapDepValContVal = parseCSVFile(); 
      system.debug('mapDepValContVal++' + mapDepValContVal);

      for (String strDepVal: mapDepValContVal.keySet()) {
         MetadataService.PicklistValue plValue = new 
         system.debug('strDepVal++' + strDepVal);
         plValue.fullName = strDepVal; // Dependent picklist value
         plValue.default_x = false; // Set default to false
         plValue.isActive = true;

         plValue.controllingFieldValues = mapDepValContVal.get(strDepVal);
      customField.picklist = pt;  

      system.debug('customField++' + customField);  
      system.debug('customFieldPicklist++' + customField.picklist);  

      MetadataService.SaveResult[] results = service.updateMetadata(new List < MetadataService.Metadata > 

As per the message says, you're trying to update values from a global picklist. And considering your scenario, verify if your result fetches with the following code:

SObjectField picklistUsingGlobal = SObjectType.MyObject__c.fields.PicklistUsingGlobal__c;
List<PicklistEntry> entries = picklistUsingGlobal.getDescribe().getPicklistValues();

If not, I'd recommend you have a look into this post Create and Update Global Value Set.

Besides, when you are deploying it using the manifest file, retrieve the global field API name (it might not come automatically)

|improve this answer|||||

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.