vijayk3327 / Lightning-Aura-Component

0 stars 0 forks source link

How to fetch picklist values from apex controller in lightning component #10

Open vijayk3327 opened 1 year ago

vijayk3327 commented 1 year ago

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>`

Step 2:- Create Lightning Component : statusCmp.cmp

`

.forceStyle.desktop .viewport{background:#fff;} ` **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"}); action.setCallback(this, function(response){ var state = response.getState(); if(state == "SUCCESS"){ var result = response.getReturnValue(); component.set('v.statusListItems',result); } }); $A.enqueueAction(action); }, })` **Step 5:- Create Lightning Application : pickListController.apxc** ` public class pickListController { @AuraEnabled public static List pickList(String obj, String str) { List regList = new List(); 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:-](https://www.w3web.net/fetch-picklist-values-dynamically/)**
amriteshsingh987 commented 11 months ago

Where is pickListController ?