You need to sign in to do that
Don't have an account?
Harshwardhan Singh Karki
How to delete the picklist value from Picklist valueset using tooling api ? Is this operation feasibe and if so , Will there also be change in json and what?
I am trying to update and remove the picklist value set using tooling api on the basis of active users in the org , i am able to update the picklist value set using json but when it comes to removing the value from ValueSet , i am unable to find any approach .
Sample Code Used While updating the picklist valueset
Http h = new Http();
Httprequest req = new Httprequest();
string json ='{"Metadata" : {"businessOwnerGroup" : null,"businessOwnerUser" : null,"businessStatus" : null,"caseSensitive" : null,"complianceGroup" : null,'+
'"customDataType" : null,"defaultValue" : null,"deleteConstraint" : null,"deprecated" : null,"description" : null,"displayFormat" : null,"displayLocationInDecimal" : null,'+
'"encryptionScheme" : null,"escapeMarkup" : null,"externalDeveloperName" : null,"externalId" : false,"formula" : null,"formulaTreatBlanksAs" : null,"inlineHelpText" : null,"isAIPredictionField" : null,'+
'"isConvertLeadDisabled" : null,"isFilteringDisabled" : null,"isNameField" : null,"isSortingDisabled" : null,"label" : "PickAUser","length" : null,"lookupFilter" : null,"maskChar" : null,"maskType" : null,'+
'"metadataRelationshipControllingField" : null,"populateExistingRows" : null,"precision" : null,"readOnlyProxy" : null,"referenceTargetField" : null,"referenceTo" : null,"relationshipLabel" : null,"relationshipName" : null,'+
'"relationshipOrder" : null,"reparentableMasterDetail" : null,"required" : false,"restrictedAdminField" : null,"scale" : null,"securityClassification" : null,"startingNumber" : null,"stripMarkup" : null,"summarizedField" : null,'+
'"summaryFilterItems" : null,"summaryForeignKey" : null,"summaryOperation" : null,"trackFeedHistory" : null,"trackHistory" : false,"trackTrending" : false,"translateData" : null,"type" : "Picklist","unique" : null,"urls" : null,'+
'"valueSet" : {"controllingField" : null,"restricted" : true,"valueSetDefinition" : {"sorted" : false,"value" : [ {"color" : null,"default" : false,"description" : null,"isActive" : null,"label" : "Amanda Deeks","urls" : null,'+
'"valueName" : "005Dn0000043JTTIA2"}, {"color" : null,"default" : false,"description" : null,"isActive" : null,"label" : "Ben Snowden","urls" : null,"valueName" : "005Dn0000043JTUIA2"},{"color" : null,"default" : false,"description" : null,'+
'"isActive" : null,"label" : "Caroline Hawkins","urls" : null,"valueName" : "005Dn000003LM7hIAG"}, {"color" : null,"default" : false,"description" : null,"isActive" : null,"label" : "Daniel Hartage","urls" : null,"valueName" : "005Dn0000043JTVIA2"'+
'} ]},"valueSetName" : null,"valueSettings" : []},"visibleLines" : null,"writeRequiresMasterRead" : null},"FullName" : "Theme_Relation__c.PickAUser__c"}';
req.setHeader('Authorization', 'Bearer' + UserInfo.getUserId());
string endpointRemainingUrl = '/services/data/v48.0/tooling/sobjects/CustomField/00NDn00000HiexxMAB';
string endpoint = Url.getSalesforceBaseUrl().toExternalForm() + endpointRemainingUrl;
req.setEndpoint(endpoint);
req.setHeader('Content-Type','application/json; charset=utf-8');
req.setBody(json);
req.setMethod('PATCH');
Httpresponse res = h.send(req);
Sample Code Used While updating the picklist valueset
Http h = new Http();
Httprequest req = new Httprequest();
string json ='{"Metadata" : {"businessOwnerGroup" : null,"businessOwnerUser" : null,"businessStatus" : null,"caseSensitive" : null,"complianceGroup" : null,'+
'"customDataType" : null,"defaultValue" : null,"deleteConstraint" : null,"deprecated" : null,"description" : null,"displayFormat" : null,"displayLocationInDecimal" : null,'+
'"encryptionScheme" : null,"escapeMarkup" : null,"externalDeveloperName" : null,"externalId" : false,"formula" : null,"formulaTreatBlanksAs" : null,"inlineHelpText" : null,"isAIPredictionField" : null,'+
'"isConvertLeadDisabled" : null,"isFilteringDisabled" : null,"isNameField" : null,"isSortingDisabled" : null,"label" : "PickAUser","length" : null,"lookupFilter" : null,"maskChar" : null,"maskType" : null,'+
'"metadataRelationshipControllingField" : null,"populateExistingRows" : null,"precision" : null,"readOnlyProxy" : null,"referenceTargetField" : null,"referenceTo" : null,"relationshipLabel" : null,"relationshipName" : null,'+
'"relationshipOrder" : null,"reparentableMasterDetail" : null,"required" : false,"restrictedAdminField" : null,"scale" : null,"securityClassification" : null,"startingNumber" : null,"stripMarkup" : null,"summarizedField" : null,'+
'"summaryFilterItems" : null,"summaryForeignKey" : null,"summaryOperation" : null,"trackFeedHistory" : null,"trackHistory" : false,"trackTrending" : false,"translateData" : null,"type" : "Picklist","unique" : null,"urls" : null,'+
'"valueSet" : {"controllingField" : null,"restricted" : true,"valueSetDefinition" : {"sorted" : false,"value" : [ {"color" : null,"default" : false,"description" : null,"isActive" : null,"label" : "Amanda Deeks","urls" : null,'+
'"valueName" : "005Dn0000043JTTIA2"}, {"color" : null,"default" : false,"description" : null,"isActive" : null,"label" : "Ben Snowden","urls" : null,"valueName" : "005Dn0000043JTUIA2"},{"color" : null,"default" : false,"description" : null,'+
'"isActive" : null,"label" : "Caroline Hawkins","urls" : null,"valueName" : "005Dn000003LM7hIAG"}, {"color" : null,"default" : false,"description" : null,"isActive" : null,"label" : "Daniel Hartage","urls" : null,"valueName" : "005Dn0000043JTVIA2"'+
'} ]},"valueSetName" : null,"valueSettings" : []},"visibleLines" : null,"writeRequiresMasterRead" : null},"FullName" : "Theme_Relation__c.PickAUser__c"}';
req.setHeader('Authorization', 'Bearer' + UserInfo.getUserId());
string endpointRemainingUrl = '/services/data/v48.0/tooling/sobjects/CustomField/00NDn00000HiexxMAB';
string endpoint = Url.getSalesforceBaseUrl().toExternalForm() + endpointRemainingUrl;
req.setEndpoint(endpoint);
req.setHeader('Content-Type','application/json; charset=utf-8');
req.setBody(json);
req.setMethod('PATCH');
Httpresponse res = h.send(req);
I would like to let you know that based on my findings also currently there is no possible way to delete the picklist values via the tooling API.
Please refer to the idea exchange post below:
Mass delete picklist values (setup)
https://ideas.salesforce.com/s/idea/a0B8W00000Gdl8uUAB/mass-delete-picklist-values-setup
There is an update that the ability to Mass Delete Inactive Unused Picklist Values Pilot is now live for Sandbox orgs. Details surrounding the pilot can be found in this Trailblazer Community group: [Pilot] Delete Inactive Unused Picklist Values. https://trailhead.salesforce.com/trailblazer-community/groups/0F94S000000H1CmSAK?tab=&sort=LAST_MODIFIED_DATE_DESC (https://trailhead.salesforce.com/trailblazer-community/groups/0F94S000000H1CmSAK?tab=&sort=LAST_MODIFIED_DATE_DESC)
Hope it helps !
Thank you.