USECASE: Fetch the picklist values from Industry field of Account sObject.
OR
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult = Account.Industry.getDescribe();
List<Schema.PicklistEntry> picklistEntries = fieldResult.getPicklistValues();
for (Schema.PicklistEntry picklistEntry : picklistEntries) {
options.add(new SelectOption(picklistEntry.getLabel(), picklistEntry.getValue()));
}
return options;
OR
List<SelectOption> options = new List<SelectOption>();
Map<String, Schema.SObjectField> fieldMap = Account.getSObjectType().getDescribe().fields.getMap();
List<Schema.PicklistEntry> picklistEntries = fieldMap.get('Industry').getDescribe().getPickListValues();
for (Schema.PicklistEntry picklistEntry : picklistEntries) {
options.add(new SelectOption(picklistEntry.getLabel(), picklistEntry.getValue()));
}
return options;
0 comments:
Post a Comment