11

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

2
  • 3
    Can't you just use describes on a field that implements it?
    – Adrian Larson
    Commented Nov 2, 2016 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
    Commented Nov 22, 2020 at 21:58

2 Answers 2

9

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();
1
  • 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. Commented Mar 1, 2019 at 19:48
18
Schema.DescribeFieldResult F = <Object_API_Name>.<Field_API_Name>.getDescribe();
Schema.sObjectField T = F.getSObjectField();
List<PicklistEntry> entries = T.getDescribe().getPicklistValues();
1
  • 4
    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
    Commented Sep 12, 2019 at 16:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .