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
PrasunnaPrasunna 

To get Picklist values from metadata

Could someone assist me in getting all picklist values (no matter what object it is but need all picklist fields and values) from metadata. As we have option to get all fields and objects using Entity definition and Field definition. But we don't have any option to get picklist values. Please let me know.

Thank you
SwethaSwetha (Salesforce Developers) 
HI Prasunna,

You can use the Schema class in Apex to dynamically retrieve picklist values for all objects and fields. Here is an example of how you can do this:
> Use the getGlobalDescribe() method to get a map of all objects in the org.
Iterate through the map and use the getDescribe() method to get the object describe result.

> Iterate through the fields of the object describe result and check if the field is of type "Picklist".

>If the field is a picklist, use the getPicklistValues() method to retrieve the picklist values.

Sample code:
Map<String, Schema.SObjectType> globalDescribe = Schema.getGlobalDescribe();
List<String> picklistValues = new List<String>();

for (String objectApiName : globalDescribe.keySet()) {
    Schema.DescribeSObjectResult objectDescribe = globalDescribe.get(objectApiName).getDescribe();
    
    for (Schema.SObjectField field : objectDescribe.fields.getMap().values()) {
        if (field.getDescribe().getType() == Schema.DisplayType.Picklist) {
            Schema.DescribeFieldResult fieldDescribe = field.getDescribe();
            List<Schema.PicklistEntry> picklistEntries = fieldDescribe.getPicklistValues();
            
            for (Schema.PicklistEntry picklistEntry : picklistEntries) {
                picklistValues.add(picklistEntry.getLabel());
            }
        }
    }
}

// Use the picklistValues list as needed

Related: https://developer.salesforce.com/forums/?id=906F0000000D6l3IAC
https://salesforce.stackexchange.com/questions/387974/how-can-i-get-picklist-values-from-custom-metadata-type
https://www.jitendrazaa.com/blog/salesforce/get-picklist-values-in-apex/

If this information helps, please mark the answer as best. Thank you