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
sruthi26sruthi26 

How to pull all the values of a multi select picklist field?

Hi,

I want to get all the values of a multi select picklist custom field, no matter what values are selected through apex code. Can anyone tell me how could I approach this? 
Best Answer chosen by sruthi26
Amit GhadageAmit Ghadage
Hi Sruthi,
Use following code snippet
 
Schema.DescribeSObjectResult objSchema = Account.sObjectType.getDescribe();
Map<String, Schema.SObjectField> fieldMap = objSchema.fields.getmap();
List<Schema.Picklistentry>fld =fieldmap.get('sfsolute__Active__c').getDescribe().getpicklistValues();
System.debug('fld'+fld);
List<String> pickList = new List<String>();

for(Schema.Picklistentry pl : fld)
{
    pickList.add(pl.getValue());
}
System.debug('pickList'+pickList);
Best Regards,
Amit Ghadage
 

All Answers

ANUJIT DASANUJIT DAS
Use describe method. dynamic apex
Amit GhadageAmit Ghadage
Hi Sruthi,
Use following code snippet
 
Schema.DescribeSObjectResult objSchema = Account.sObjectType.getDescribe();
Map<String, Schema.SObjectField> fieldMap = objSchema.fields.getmap();
List<Schema.Picklistentry>fld =fieldmap.get('sfsolute__Active__c').getDescribe().getpicklistValues();
System.debug('fld'+fld);
List<String> pickList = new List<String>();

for(Schema.Picklistentry pl : fld)
{
    pickList.add(pl.getValue());
}
System.debug('pickList'+pickList);
Best Regards,
Amit Ghadage
 
This was selected as the best answer
EldonEldon
Hi sruthi,

Create a class like this below 
 
public class GetPicklistValues {
    
    public static list<string> PickThePicklist(string YourObjectName,string YourFieldName){
        
        list<string> picklists=new List<string>(); 
        List<Schema.PicklistEntry> PicklistValues  = Schema.getGlobalDescribe().get(YourObjectName).getDescribe().fields.getMap().get(YourFieldName ).getDescribe().getPicklistValues();               
        
        for( Schema.PicklistEntry PicklistValue : PicklistValues){
            picklists.add(string.valueof(PicklistValue.getLabel()));
        }
        return picklists;
    }
}

And invoke the method from your code with your object name and field name as parameters like below

 
list<string> str= GetPicklistValues.PickThePicklists('Account','Industry');
system.debug('str'+str);

Let me know if you have any problem
Close the thread by marking it as best answer if it solved your req

Regards