Is it possible to retrieve the values of a Global Picklist/GlobalValueSet using Schema class without a SOQL ?

  • 3
    Can't you just use describes on a field that implements it? – Adrian Larson Nov 2 '16 at 23:48
  • @AdrianLarson - what if a field does use it? for example a Global Value Set which is used with Custom Settings which does not support picklist – Robs Nov 22 '20 at 21:58

My strategy here would simply be to describe a picklist field that implements the Global Picklist.

SObjectField picklistUsingGlobal = SObjectType.MyObject__c.fields.PicklistUsingGlobal__c.getSObjectField();
List<PicklistEntry> entries = picklistUsingGlobal.getDescribe().getPicklistValues();
  • 5
    I get Compile failure on line 1, column 14: Illegal assignment from Schema.DescribeFieldResult to Schema.SObjectField using this snippet on Contact.Custom_Field_With_Value_Set__c. Using Hari's snippet all works fine. – Swisher Sweet Mar 1 '19 at 19:48
Schema.DescribeFieldResult F = <Object_API_Name>.<Field_API_Name>.getDescribe();
Schema.sObjectField T = F.getSObjectField();
List<PicklistEntry> entries = T.getDescribe().getPicklistValues();
  • 2
    But how can you tell if a field is employing a global value set? Where can you access that dependency information? For example, I want to loop around all the fields in my object and preform a task only if that field uses a particular global value set. Use of that GVS groups these fields together by purpose. To pick a field that is 'known' to be using a GVS requires information that should not be necessary. – Flippsie Sep 12 '19 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.