64、通过PickListValuesUtil,Schema查看下拉列表中的值
public class PickListValuesUtil { public static Map<String,Object> getPicklistValues(String sObjectName,String sFieldName){ Map<String,Object> picValues = new Map<String,Object>(); Map<String,Schema.SObjectType> sObjectDescribeMap = Schema.getGlobalDescribe(); if(sObjectDescribeMap.containsKey(sObjectName)){ Map<String,Schema.SObjectField> sObjectFieldMap = sObjectDescribeMap.get(sObjectName).getDescribe().fields.getMap(); if(sObjectFieldMap.containsKey(sFieldName)){ Schema.DescribeFieldResult sObjectFieldDescribe = sObjectFieldMap.get(sFieldName).getDescribe(); List<Schema.PicklistEntry> lPickEntryList = sObjectFieldDescribe.getPicklistValues(); for (Schema.PicklistEntry tPicklistEntry : lPickEntryList){ picValues.put(tPicklistEntry.getValue(), new Map<String,object>{ 'value'=>tPicklistEntry.getValue(), 'isActive'=>tPicklistEntry.getValue(), 'isDefaultValue'=>tPicklistEntry.isDefaultValue(), 'label'=>tPicklistEntry.getLabel() }); } }else{ } }else{ } return picValues; } }
下面是调用部分
Map<String,Object> invoice_c = PickListValuesUtil.getPicklistValues('Invoice__c','Status__c');
System.debug(invoice_c);
输出的结果如下图所示
15:32:13:022 USER_DEBUG [2]|DEBUG| { Closed={isActive=Closed, isDefaultValue=false, label=Closed, value=Closed}, Negotiating={isActive=Negotiating, isDefaultValue=false, label=Negotiating, value=Negotiating}, Open={isActive=Open, isDefaultValue=true, label=Open, value=Open},
Pending={isActive=Pending, isDefaultValue=false, label=Pending, value=Pending} }