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
Carly Probasco 14Carly Probasco 14 

Display picklist value in a lighting component

I'm having trouble displaying a picklist value in a ligthning component. See below for methods used. What am I missing?

I have added a new picklist field the query in a controller, and I'm using these methods to return the picklist values used in the Lighting Component:
//Grabs options for all picklists on the page.   @AuraEnabled   public static List<returnFieldOptions> getPicklistOptions(string picklistFieldsJson){     System.debug('Picklist Fields Json: '+picklistFieldsJson);          //Create new list of return options for returning picklists to the page (returnFieldOptions class defined at bottom of this page).     List<returnFieldOptions> allFieldOptions = new List<returnFieldOptions>();     //Turn the JSON received from the page into a list of a custom class (defined at bottom of the page).     List<fieldLookups>picklistFields = (List<fieldLookups>)System.JSON.deserializeStrict(picklistFieldsJson,List<fieldLookups>.Class);     //For each item received, find all the fields and put them into the allFieldOptions list.     for(fieldLookups fieldInfo : picklistFields){       System.debug(fieldInfo);       //Create object for returning picklist fields and instantiate the list where we will be storing the values.       returnFieldOptions targetFieldOptions = new returnFieldOptions();       targetFieldOptions.picklistOptions = new List<String>();       //Add in the attribute name where this will be stored when it goes back to the page. Add "--None--" as the first option.       targetFieldOptions.attributeName = fieldInfo.attributeName;       targetFieldOptions.picklistOptions.add('--None--');       //Retrieve object metadata.       Schema.sObjectType targetObjectType = Schema.getGlobalDescribe().get(fieldInfo.objectName);       Schema.DescribeSObjectResult targetObjectDescribe = targetObjectType.getDescribe();       Map<String, Schema.SObjectField> fieldMap = targetObjectDescribe.fields.getMap();                          system.debug(fieldInfo.fieldName);       //Retrieve picklist options for the specific field.       List<Schema.PicklistEntry> values = fieldMap.get(fieldInfo.fieldName).getDescribe().getPicklistValues();       //Add their name to the return object list as a string.       for(Schema.PicklistEntry a: values){         targetFieldOptions.picklistOptions.add(a.getValue());       }       //Add the return object for this picklist to the overall list that will go back to the page.       allFieldOptions.add(targetFieldOptions);     }     System.debug(allFieldOptions);     return allFieldOptions;   }  }   public class fieldLookups {     Public string attributeName{get;set;}     Public string objectName {get;set;}     Public string fieldName {get;set;}   }   public class returnFieldOptions{     @AuraEnabled     Public string attributeName{get;set;}     @AuraEnabled     Public List<String>picklistOptions{get;set;}   }



Here is the Lighting Component:
<aura:attribute name="RequestChangeOptions" access="private" type="String[]"/> <div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1"> <lightning:select name="RequestChangeSelect" label="Request Change to Classroom?" value="{!v.SelectedClassroom.Provider_Request_Classroom_Changes__c}" required="true"> <aura:iteration items="{!v.RequestChangeOptions}" var="RequestClassroomChange"> <option text="{!RequestClassroomChange}"></option> </aura:iteration> </lightning:select>

 
Best Answer chosen by Carly Probasco 14
vishal-negandhivishal-negandhi

This is apex controller, you need to create a javascript controller for your aura component. 

Look at this example - https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm

You can call your method in apex controller from the javascript controller of your aura component. Too many controllers, might be confusing but the documentation and trailhead should help. 

 

All Answers

vishal-negandhivishal-negandhi

Hi Carly, 

I don't see the aura component's javascript controller where you're making a call to your apex controller which will invoke the controller method?

Carly Probasco 14Carly Probasco 14
Hi Vishal-Negandhi,
<aura:component controller="ClassroomManagerComponentApexController">

 
vishal-negandhivishal-negandhi

This is apex controller, you need to create a javascript controller for your aura component. 

Look at this example - https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm

You can call your method in apex controller from the javascript controller of your aura component. Too many controllers, might be confusing but the documentation and trailhead should help. 

 

This was selected as the best answer
Carly Probasco 14Carly Probasco 14
@Vishal-Neganhi, thank you :)