I would love to be able to update picklist values through the Metadata API. However, some of my changes are nothing but case-correction (e.g., replacing, "Hi there" with "Hi There").

I understand from multiple sources (RTFM here) that it's impossible to remove picklist values through the Metadata API. Is there a way to replace values with their case-corrected versions, or even just to add the case corrected versions?


1 Answer 1


Using the metadata api apex wrapper (https://github.com/financialforcedev/apex-mdapi) you can modify values of picklist.

Steps are as following:

1- Deploy the metadata api apex wrapper into your org.

2- Modify the CustomValue class included in the MetadataService class including this new values:

public virtual class CustomValue extends Metadata {
        public String type = 'CustomValue';
        public String fullName;
        private String[] fullName_type_info = new String[]{'fullName',SOAP_M_URI,null,'0','1','false'};
            public String color;
        public Boolean default_x;
        public String description;
        public Boolean isActive;
        public String label;
        private String[] color_type_info = new String[]{'color',SOAP_M_URI,null,'0','1','false'};
            private String[] default_x_type_info = new String[]{'default',SOAP_M_URI,null,'1','1','false'};
                private String[] description_type_info = new String[]{'description',SOAP_M_URI,null,'0','1','false'};
                    private String[] isActive_type_info = new String[]{'isActive',SOAP_M_URI,null,'0','1','false'};
                        private String[] label_type_info = new String[]{'label',SOAP_M_URI,null,'0','1','false'};
                            private String[] apex_schema_type_info = new String[]{SOAP_M_URI,'true','false'};
                                private String[] field_order_type_info = new String[]{'fullName','color','default_x','description','isActive','label'};

3-Create your code to modify your picklist values as desired. I attach a code to for example modify the value 'WebCampaign2019' of


picklist of the object Account to be 'WEBCAMPAIGN2019'.

        String picklistapiname = 'Account.Source_Specification__c';
        MetadataService.MetadataPort service = new MetadataService.MetadataPort();   
        service.SessionHeader = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId = UserInfo.getSessionId();
        MetadataService.CustomField customField = (MetadataService.CustomField) service.readMetadata('CustomField', new String[] { picklistapiname}).getRecords()[0];

        for(MetadataService.CustomValue picklistValue : customField.valueSet.ValueSetDefinition.value){
            if(picklistValue.fullName!=null &&  picklistValue.fullName.equals('WebCampaign2019')){
                picklistValue.fullName = 'WEBCAMPAIGN2019';
                picklistValue.Label = 'WEBCAMPAIGN2019';
        List<MetadataService.SaveResult> lstResults = service.updateMetadata( new MetadataService.Metadata[] { customField });

4- Done.

PicklistValues Before Executing Script ExecutingScript Refreshing PicklistValues After executing Script

  • Does this work for the replacement of options of a different case? Feb 9, 2020 at 19:35
  • Sorry, maybe it's because of the choice of words, but I don't understand what you mean, could you rephrase it, please? Feb 10, 2020 at 8:42
  • The original question asked how to change the case of a picklist option using the metadata api. For example, SUPER when Super is already an option. Feb 10, 2020 at 14:40
  • The option on the picklist is modificable.The issue is that the data is not updated acordingly since the old value is moved to inactive values and I couldn't achieve to delete picklist values using the wrapper metadata api. If that was possible I think it would be smooth to do a full substitution of picklist metadata values and data values on DB. But atm I only know how to substitut metadata values on the picklist. Feb 10, 2020 at 14:48
  • Or simply correcting the case of Super to SUPER Feb 10, 2020 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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