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
Bhola VishwakarmaBhola Vishwakarma 

how to get all the picklist value using soql query

any query to get all the piclist values

Ankit AroraAnkit Arora

If you want all values in picklist field on object then it is not possible from SOQL. You need to use the describe call.

 

Here is the code :

 

            //use GlobalDecribe to get a list of all available Objects
            Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
            Set<String> objectKeys = gd.keySet();
            for(String objectKey: objectKeys)
            {
                //Iterate through all objects to locate ACCOUNT Object
                if (objectKey == 'account')
                {
                    Schema.SObjectType systemObjectType = gd.get(objectKey);
                    Schema.DescribeSObjectResult r = systemObjectType.getDescribe();
                    Map<String, Schema.SObjectField> M = r.fields.getMap();
                    Set<String> fieldNames = M.keySet();
                     //iterate through all fields of the object to locate the field
                    for(String fieldName: fieldNames)
                    {
                        if (fieldName == 'industry')
                        {
                            Schema.SObjectField field = M.get(fieldName);
                            Schema.DescribeFieldResult fieldDesc = field.getDescribe();
                            //extract the picklist values
                            System.debug(fieldDesc.getPicklistValues() + ' ::::::::::::::::::::::::::::::::::: ') ;
                        }
                    }
                }
              }

 You can change the object name here :

 

 if (objectKey == 'account')

 And the picklist field name here :

 

if (fieldName == 'industry')

 

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

chadwtaylorchadwtaylor

I'm trying to get all list of CASE TYPE (picklist) under CASE.

 

According to you, it's not possible from SOQL, correct?  If so, can you provide a sample on how I can achieve this through Ruby (ie: I'm using databasedotcom gem).

 

Any pointers will be greatly appreciated. 

 

Thanks,

Chad

Prudhvi A 15Prudhvi A 15
We can retrieve without writing web service using standard REST API call with tooling API.
 
Step1: Get list of existing Global picklist set ID's using below REST Endpoint URI
 
Step2: Pass picklist set Id and get the picklist values using below REST Endpoint URI
 
  • Workbench End Point:  
    • URI: /services/data/v41.0/tooling/sobjects/GlobalValueSet/0NtXXXXXX
  • General End Point:
    • URI:https://naXX.salesforce.com /services/data/v41.0/tooling/sobjects/GlobalValueSet/0NtXXXXXX

Blog link: http://www.lwcforce.com/2020/07/retrieve-global-picklist-values-using.html
Richard Fiekowsky 3Richard Fiekowsky 3
Note that the getDescribe only returns active values. Also, if the field's properties do not restrict it to active values, a new inactive value is created when a user saves a record with a value that isn't on the list. These values can be found only on the data records (and in Setup); no PicklistEntry is created.   
Akhila NathanAkhila Nathan

Hi All,

It is possible to query the values and labels using 3 SOQL queries:

1. To find the object details:

SELECT Id, DurableId, QualifiedApiName, DeveloperName, MasterLabel, Label from EntityDefinition


2. To find the fields involved in the object, 'objectname':

SELECT Id, EntityDefinitionId, QualifiedAPIName, FieldDefinitionId FROM EntityParticle WHERE EntityDefinition.QualifiedApiName ='objectname'


3. To fetch the values involved in that particular picklist field. Id represents FieldDefinitionId minus EntityDefinitionId:

SELECT Id,isdefaultValue,durableId,validFor, label,value FROM PicklistValueInfo Where EntityParticle.FieldDefinitionId ='objectname.Id'



Warm Regards,
Akhila

Henry ChiuHenry Chiu
Thank you Akhila Nathan, your answer is the best answer.