Is it possible to retrieve the values of a Global Picklist/GlobalValueSet using Schema class without a SOQL ?
2 Answers
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();
-
5I get
Compile failure on line 1, column 14: Illegal assignment from Schema.DescribeFieldResult to Schema.SObjectField
using this snippet onContact.Custom_Field_With_Value_Set__c
. Using Hari's snippet all works fine. Commented Mar 1, 2019 at 19:48
Schema.DescribeFieldResult F = <Object_API_Name>.<Field_API_Name>.getDescribe();
Schema.sObjectField T = F.getSObjectField();
List<PicklistEntry> entries = T.getDescribe().getPicklistValues();
-
4But 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.– FlippsieCommented Sep 12, 2019 at 16:03
-
In Setup, open a Picklist Value Set. There's a Fields Where Used table in the page. Obviously this approach is somewhat fragile, since there's no indication on the field itself that this dependency is being assembled, but you could create a dummy field just for the purpose and mention the controller in its description. Commented Oct 16 at 20:13
Global Value Set
which is used withCustom Settings
which does not supportpicklist