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
Mohit Gupta 125Mohit Gupta 125 

Get all picklist values using SOQL

I want to pick all values of a particular field which is a 'PickList' (say the field name is ABC)

I tried using the below query which this field is part of (say XYZ).

My query is

Select toLabel(ABC)  FROM XYZ 

But this is only giving me those Picklist values which are part of XYZ/ or selected at least in one of the XYZ item.

I want the entire master list of PickList values of ABC.

How can I do it using SOQL?
Thanks
 

Best Answer chosen by Mohit Gupta 125
Mohit Gupta 125Mohit Gupta 125
Solved it by pulling entire XYZ object using Rest Call

All Answers

Steven NsubugaSteven Nsubuga
SOQL is not the best option for this requirement. Use a Field Describe.
List<String> pickListValuesList= new List<String>();

List<Schema.PicklistEntry> picklistEntry = XYZ__c.ABC__c.getDescribe().getPicklistValues();

for( Schema.PicklistEntry pickListVal : picklistEntry){
	pickListValuesList.add(pickListVal.getLabel());
}

 
Mohit Gupta 125Mohit Gupta 125
I am using C# and using Force.NET , can you please help if that is possible using C#
Mohit Gupta 125Mohit Gupta 125
Solved it by pulling entire XYZ object using Rest Call
This was selected as the best answer
Ajay K DubediAjay K Dubedi
Hi Mohit,

If you want to display picklist values in your custom page through dynamic apex.Y ou can check below link it will help.

https://developer.salesforce.com/blogs/developer-relations/2008/12/using-the-metadata-api-to-retrieve-picklist-values.html

Below code can fulfill your requirements. Hope this will work for you.
 
public List<String> getPickListValuesIntoList(){
       List<String> pickListValuesList= new List<String>();
        Schema.DescribeFieldResult fieldResult = ObjectApiName.FieldApiName.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry pickListVal : ple){
            pickListValuesList.add(pickListVal.getLabel());
        }    
        return pickListValuesList;
    }
    
Please mark this as best answer if this solves your problem.

Thank you
Ajay Dubedi