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
Sandeep Rahul PVSandeep Rahul PV 

How to add and remove values from Picklist Value sets (Global Pick list) ?

Hi Team,
 
I have created a Picklist Value set and I referred this to a custom picklist field. Now the requirement is I need to update the Picklist value set through apex on the batch run. Help me. 

Thank you
Sandeep.

User-added image

AshwiniAshwini (Salesforce Developers) 
Hi Sandeep,
To access picklist values from a trigger or server controller in Apex, you can use dynamic Apex. It lets you analyze objects and fields programmatically with methods from the Schema namespace. (https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_Schema.htm
The following code sample shows how you can retrieve picklist values for the “Industry” field of the “Account” object as a list of Schema.PicklistEntry (https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_Schema_PicklistEntry.htm) using getDescribe() and getPicklistValues():
// Describe the Account.Industry field
Schema.DescribeFieldResult fieldDescription = Account.Industry.getDescribe();
// Get picklist values from field description
List entries = fieldDescription.getPicklistValues();
// Do something with entries
for (Schema.PicklistEntry entry : entries) {
/*
entry.getValue()
entry.getLabel()
entry.isActive()
entry.isDefaultValue()
*/
}
Related:
https://www.phoneiq.co/blog/how-to-check-picklist-values-with-apex-in-salesforce 
https://developer.salesforce.com/blogs/developer-relations/2008/12/using-the-metadata-api-to-retrieve-picklist-values 
 https://help.salesforce.com/s/articleView?id=sf.updating_picklists.htm&type=5
https://github.com/pozil/picklist-utils 

Thanks.