function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ranjith DevRanjith Dev 

How to resolve the FIELD_INTEGRITY_EXCEPTION through Tooling api integration while upserting the Global picklist value set

Hi Team,

we have faced the FIELD_INTEGRITY_EXCEPTION issue while updating the Global picklist values (assigned for field in Sobject). 
    This update has been done through scheduled jobs. Initially it was done for the first schedule run when files are different and after the next schedule run it will not work.
    FYI : capture the error from debug log
    httpres.getBody()==>[{"message":"Duplicate label: Company dell","errorCode":"FIELD_INTEGRITY_EXCEPTION","fields":[]}]
  
    Please find the below snippet code:
    
    string metadataPicklistPrepation='{"Metadata":{"customValue":[';
        for(listvaluesWrap picklist: results.value){
            string PickDesc = picklist.Description;
            string DescrptnUpperacse = null;
            DescrptnUpperacse = PickDesc.toUpperCase();
            system.debug('DescrptnUpperacse==>'+DescrptnUpperacse);
            metadataPicklistPrepation=metadataPicklistPrepation+'{"color":null,"default":false,"description":null,"isActive":null,';
            metadataPicklistPrepation=metadataPicklistPrepation+'"label":"'+DescrptnUpperacse+'","urls":null,"valueName":"'+picklist.code+'"},';  //picklist.code          
            
        }
        metadataPicklistPrepation=metadataPicklistPrepation.removeEnd(',');
        metadataPicklistPrepation = metadataPicklistPrepation + '],';
        metadataPicklistPrepation=metadataPicklistPrepation+'"description":null,"masterLabel":"All Provider Types","sorted":false,"urls":null},"FullName":"All_Provider_Types"}';
        system.debug('metadataPicklistPrepation==>'+metadataPicklistPrepation);
        
        JSONParser parser = JSON.createParser(resBody);
        listvaluesWrap wrapvalues = new listvaluesWrap();        
        
        HttpRequest reqt = new HttpRequest();
        reqt.setBody(metadataPicklistPrepation);
        reqt.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
        reqt.setHeader('Content-Type', 'application/json');      
        reqt.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v41.0/tooling/sobjects/GlobalValueSet/0Ntt0000000Kzjc?_HttpMethod=PATCH');//replace id with your GlobalPicklist Id**
        reqt.setMethod('POST');
        reqt.setTimeout(12000);
        Http httpreq = new Http();
        HttpResponse httpres  = httpreq.send(reqt);



Thank you,
Ranjith M
  
VinayVinay (Salesforce Developers) 
Hi Ranjith,

Check below link that has similar issue and that can help you.

https://salesforce.stackexchange.com/questions/217309/create-update-global-value-set-using-tooling-api

Thanks,
RituSharmaRituSharma
See these 2 lines:
reqt.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v41.0/tooling/sobjects/GlobalValueSet/0Ntt0000000Kzjc?_HttpMethod=PATCH');//replace id with your GlobalPicklist Id**
reqt.setMethod('POST');

In first line, method is PATCH but in second line, it's POST.

Change as below and then try:
reqt.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm()+'/services/data/v41.0/tooling/sobjects/GlobalValueSet/0Ntt0000000Kzjc');//replace id with your GlobalPicklist Id**
reqt.setMethod('PATCH');