You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
action.setCallback(this, function(response){
var state = response.getState();
if(state == "SUCCESS"){
var result = response.getReturnValue();
component.set('v.statusListItems',result);
}
});
$A.enqueueAction(action);
},
In this post we are going to learn about how to retrieve Picklist values from Apex controller in Lightning Component.
→ Get source code live demo link:-
Step 1:- Create Lightning Application : statusApp.app
<aura:application extends="force:slds"> <c:statusCmp/> </aura:application>
Step 2:- Create Lightning Component : statusCmp.cmp
` <aura:component controller="pickListController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction,lightning:actionOverride" access="global" >
<aura:html tag="style">.forceStyle.desktop .viewport{background:#fff;}</aura:html>
<aura:attribute name="coursesObj" type="Course__c" default="{'sobjectType':'Course__c'}"/>
<aura:attribute name="statusListItems" type="Course__c[]"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
</aura:component>`
Step 3:- Create Lightning Component : statusCmpController.js
({ doInit:function(component, event, helper){ helper.statusListItemsView(component); }, })
Step 4:- Create Lightning Component : statusCmpHelper.js
` ({
statusListItemsView : function(component, event, helper) {
var action = component.get('c.pickList');
action.setParams({"obj":"Course__c", "str":"Status__c"});
})`
Step 5:- Create Lightning Application : pickListController.apxc
public class pickListController { @AuraEnabled public static List<String> pickList(String obj, String str) { List<String> regList = new List<String>(); Schema.DescribeFieldResult plistvalues = Schema.getGlobalDescribe().get(obj).getDescribe().fields.getMap().get(str).getDescribe(); for(PicklistEntry ent:plistvalues.getpicklistvalues()) { regList.add(ent.getLabel()); } return regList; } }
→ Get source code live demo link:-
The text was updated successfully, but these errors were encountered: