function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
M.sfM.sf 

How to get select option return type in aura enabled methods?

If the return type in aura enabled method is returning and error and not able to solve. Is there any options apart from adding new class to enable aura to select option class?
@AuraEnabled
    public List<SelectOption> getObjDetails() {
    //do something
}
EldonEldon
Hi,
Try making your function as static as below,

@AuraEnabled
    public static List<SelectOption> getObjDetails() {
    //do something
}
M.sfM.sf
Hi Eldon,
Thanks for reply. I tried that previosuly no luck Below is the error.
Error: Compile Error: Return type does not support AuraEnabled at line ** column **
EldonEldon
Please share your apex code so that we can look into it.
M.sfM.sf
Since select options were not support we used maps instaed for the same
@ M  Coder@ M Coder
hi , we can use list<string> also apart from maps ... 
sfdcMonkey.comsfdcMonkey.com
hi M Coder
yes you can
check similar post here for return select options from auraEnabled methods
http://www.sfdcmonkey.com/2016/12/05/how-to-fetch-picklist-value-from-sobject-and-set-in-uiinputselect/
Hops it helps
thanks
 
Mohit Gupta SlalomMohit Gupta Slalom
Hi,

You can do a workaround to SelectOption class, by creating a your custom SelectOption class. See below, this a very simple with label and value options only, you can build on this and add new constructors and variables.
 
public class CustomSelectOptions{
	@AuraEnabled String label {get;set;}
	@AuraEnabled String value {get;set;}

	public CustomSelectOptions() {
		this.label = '';
		this.value = '';
	}

	public CustomSelectOptions(String lab, String val) {
		this.label = lab;
		this.value = val;
	}
}

Now you can use this class for your getPicklistValue Method. See Below:
 
public static List<CustomSelectOptions> getPicklistValues(String sObj, String field) {
	List<CustomSelectOptions> options = new List<CustomSelectOptions>();
	Map<String, Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get(sObj).getDescribe().fields.getMap();
	Schema.SObjectField sObjfield = fieldMap.get(field);
	Schema.DescribeFieldResult fieldDesc = sObjfield.getDescribe();
	List<Schema.PicklistEntry> ple = fieldDesc.getPicklistValues();
        for( Schema.PicklistEntry f : ple) {
		options.add(new CustomSelectOptions(f.getLabel(), f.getValue());
   	}       
   	return options;
}