Hey guys, today in this post we are going to learn about How to get all values from List Custom Setting Using Apex Class Method in Lightning Component Salesforce
Files we used in this post example
myCustomSettingApp.app | Lightning Application | It is used for call the component to preview on browser. |
myCustomSettingCmp.cmp | Lightning Component | It is used for create a table for display the Custom Setting’s Values |
myCustomSettingCmpController.js | JavaScript Controller File | It is hold Javascript doInit functionality. |
myCustomSettingCmpHelper.js | JavaScript Controller Helper File | It is hold for Javascript Helper Function to get Custom setting values from apex method |
myCustomSettingCtrl.apxc | Apex Class Controller | It is used for get Custom setting values from Apex Class Method |
Live Demo
Other related post that would you like to learn in LWC
Step 1:- Create Lightning Application : myCustomSettingApp.app
From Developer Console >> File >> New >> Lightning Application
myCustomSettingApp.app [Component Application File]
1 2 3 |
<aura:application extends="force:slds"> <c:myCustomSettingCmp/> </aura:application> |
Step 2:- Create Lightning Component : myCustomSettingCmp.cmp
From Developer Console >> File >> New >> Lightning Component
myCustomSettingCmp.cmp [Lightning Component File]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<aura:component controller="myCustomSettingCtrl" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" > <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> <aura:attribute name="studentInfoList" type="List" /> <div class="slds slds-p-horizontal--medium"> <h2></h2> <br/> <table class="slds-table slds-table--bordered slds-table--col-bordered" style="width:50%; border:1px #ddd solid;"> <thead> <tr style="background-color:#ddd;"> <th style="background:#eee;">Student Name</th> <th style="background:#eee;">Course</th> <th style="background:#eee;">Course Duration</th> <th style="background:#eee;">City</th> </tr> </thead> <tbody> <aura:iteration items="{!v.studentInfoList}" var="listItem"> <tr> <td>{!listItem.Student_Name__c}</td> <td>{!listItem.Course__c}</td> <td>{!listItem.Course_Duration__c}</td> <td>{!listItem.City__c}</td> </tr> </aura:iteration> </tbody> </table> </div> </aura:component> |
Step 3:- Create Lightning Component : myCustomSettingCmpController.js
From Developer Console >> File >> New >> Lightning Component >> JavaScript Controller
myCustomSettingCmpController.js [JavaScript Controller]
1 2 3 4 5 6 |
({ doInit: function(component, event, helper) { helper.studentInfoHelper(component, event, helper); }, }) |
Step 4:- Create Lightning Component : myCustomSettingCmpHelper.js
From Developer Console >> File >> New >> Lightning Component >> JavaScript Helper
myCustomSettingCmpHelper.js [JavaScript Helper File]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
({ studentInfoHelper : function(component, event, helper) { var action = component.get("c.studentInfoDetails"); action.setCallback(this, function(response) { var state = response.getState(); if (state === "SUCCESS") { var results= response.getReturnValue(); //alert(JSON.stringify(results)); component.set("v.studentInfoList", results); } }); $A.enqueueAction(action); }, }) |
Step 5:- Create Apex Class : myCustomSettingCtrl.apxc
From Developer Console >> File >> New >> Apex Class
myCustomSettingCtrl.apxc [Apex Class Controller]
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public class myCustomSettingCtrl { @AuraEnabled public static List<Student_Information__c> studentInfoDetails() { List<Student_Information__c> studentInfoList = Student_Information__c.getAll().values(); return studentInfoList; } } |
Further post that would you like to learn