I'm trying to update a global value set, using Tooling API.

My issue is when I update the global picklist - if I have values in it that does not exist in my new JSON - it's putting them as inActive.

I wish to update the values - if the API is the same, or create new ones if it does not exist in the picklist, and remain the existing values.

What did so far -

  public class RootObjectMeta{
        Metadata metadata;
        public String fullName;

    public class Metadata {
        public List<CustomValue> customValue;
        public Object description;
        public String masterLabel;
        public Boolean sorted;

    public class CustomValue {
        public Object color;
        // public Boolean default;
        public Object description;
        public Object isActive;
        public String label;  
        public String valueName;

//Having a service which returns the picklist values I need from another system - I inserted it to a Map<String,String> (Value , label) - called : codeandDesctions

 RootObjectMeta rootObjMeta = new RootObjectMeta();

        rootObjMeta.fullName = 'Reasons';
        Metadata m = new Metadata();
        m.description = 'Test';
        m.masterLabel = 'Reasons';
        m.sorted = false;

        List<CustomValue> cv = new List<CustomValue>();
        CustomValue cv1;

        for(String s : codeandDesctions.keySet()){ //(Value - label Map)

                cv1 = new CustomValue();
                cv1.color = null;
                //cv1.default = false;
                cv1.description = null;
                cv1.valueName = s;
    m.CustomValue = cv;
    rootObjMeta.metadata = m;

    String stringJson = JSON.serializePretty(rootObjMeta);
    HttpRequest req = new HttpRequest();
    req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
    req.setHeader('Content-Type', 'application/json');      
    Http httpreqMeta = new Http();
    HttpResponse res  = httpreqMeta.send(req);

For example:

if I have a global picklist with the values : label: code 1 , value: 1

and the JSON with the picklist value have the values: code 1 => 1 , code 2 => 2

The label: code 2 => 2 - will appear next to my existing code 1 => 1.

But if the json return only code 2 => 2, it will make code 1 => 1 inactive.

What I wish to achieve: for scenario 2 : code 2 => 2 will be added and code 1 => 1 will stay active.

I got helped from: Create/Update Global Value Set using Tooling API

Hope this is clear enough,


1 Answer 1


Any values not specified will be made invalid. That's how the API works. You need to first retrieve the values, then update the list.

  • Thanks @sfdcfox
    – Salvation
    Dec 7, 2020 at 15:53

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.