I have these two functions that are very similar. They retrieve picklist values for my aura components.
@AuraEnabled(cacheable=true)
public static List<Map<String,String>> getStatusPicklistValues() {
List<Map<String,String>> statuses = new List<Map<String,String>>();
for(Schema.PicklistEntry e : Case.Status.getDescribe().getPicklistValues()) {
if(e.isActive()) {
statuses.add(
new Map<String, String> {
'label' => e.getLabel(),
'value' => e.getValue()
}
);
}
}
return statuses;
}
@AuraEnabled(cacheable=true)
public static List<Map<String,String>> getCustomFieldPickListValues() {
List<Map<String,String>> values = new List<Map<String,String>>();
for(Schema.PicklistEntry e : Case.Custom_Field__c.getDescribe().getPicklistValues()) {
if(e.isActive()) {
values.add(
new Map<String, String> {
'label' => e.getLabel(),
'value' => e.getValue()
}
);
}
}
return values;
}
It would be nice if I could have one function like this
@AuraEnabled(cacheable=true)
public static List<Map<String,String>> getPickListValues(String fieldName) {
List<Map<String,String>> values = new List<Map<String,String>>();
for(Schema.PicklistEntry e : Case[fieldName].getDescribe().getPicklistValues()) {
if(e.isActive()) {
values.add(
new Map<String, String> {
'label' => e.getLabel(),
'value' => e.getValue()
}
);
}
}
return values;
}
Is that possible?