What is failing here perfectly works for a SysAdmin user. I have a StandardUser with a permission set which grants him ModifyMetadata and calling this code creates the Picklist Value but leaves it inactive:

public without sharing class MyClass {

    private static void updateValueSet(Set<String> newTopics, String fieldName) {
        MetadataService.MetadataPort mdapi = new MetadataService.MetadataPort();
        mdapi.SessionHeader = new MetadataService.SessionHeader_element();
        mdapi.SessionHeader.sessionId = UserInfo.getSessionId();

        MetadataService.CustomField fieldMdApi = (MetadataService.CustomField)
                                        mdapi.readMetadata('CustomField', new String[] { fieldName }).getRecords()[0];

        for(String missing : newTopics) {
            MetadataService.CustomValue value = new MetadataService.CustomValue();
            value.fullName = missing;
            value.default_x = false ;
            value.isActive = true;


        mdapi.updateMetadata(new List<MetadataService.Metadata>{ fieldMdApi });
  • Just out of curiosity... Have you tried to use metadata api to deploy same field (with picklist values as a zip file and ant/workbench) using user with Standard Profile? – kurunve Jul 11 at 22:51
  • @kurunve no and that not the point. The field already exists and just need new active values – Robert Sösemann Jul 11 at 23:56
  • 2
    Had a very similar issue. Have you tried to set the „modify all data“ system permission set? I was not very happy to set it but it worked – utm Jul 13 at 5:05
  • To be honest I don't want to give this perm to standard users – Robert Sösemann Jul 13 at 8:06

Your Answer

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

Browse other questions tagged or ask your own question.