Get Picklist Values Dynamically and display Picklist values & Radio Buttons value in Lightning Component Salesforce | how to get radio button and picklist value in lightning component

4,235 views

Hey guys, today in this post we are going to learn about How to Get Picklist Values Dynamically and display Picklist values & Radio Buttons value in Lightning Component Salesforce.

Files we used in this post example

dropdownCmpApp.app Lightning Application It is used for call the component to preview on browser
dropdownCmp.cmp Lightning Component It is used for create a picklist and radio button on lightning component.
dropdownCmpController.js JavaScript Controller File It is hold Javascript doInit and picklist change functionality to display picklist and radio values in lightning component.
dropdownCmpHelper.js JavaScript Controller Helper File It is hold Javascript Helper Function
dropdownCmpCtrl.apxc Apex Class Controller It is used to get picklist value from sObject throgh apex method
scoreCard__c Custom Object Custom Object to use get picklist values dynamic
targetVSActuals__c Custom Fields Custom Object Picklist Values

Sales Target
Score Value
Actual Sales
Achievement %
Collections Target
Actual Collections

Live Demo

display picklist and radio values in lightning component -- w3web.net

 

You can download file directly from github by Click Here.

Why Should You Schedule Meeting?

🎯 If You Are Facing Any Of These 6 Challenges. Schedule Meeting With Me.

  • Learn Salesforce Development
  • Career Confusion
  • No Interview Call
  • Low Salary
  • No Promotion/Growth
  • No Finding New Job Opportunity
  • Why you stucking from past so many years in same company?

 

 

 

Other related post that would you like to learn in Salesforce

 

Create Lightning Application

Step 1:- Create Lightning Application : dropdownCmpApp.app

From Developer Console >> File >> New >> Lightning Application

dropdownCmpApp.app [Lightning Component Application]

  1.    <aura:application extends="force:slds">
  2.     <c:dropdownCmp/>
  3. </aura:application>

Create Lightning Component

Step 2:- Create Lightning Component : dropdownCmp.cmp

From Developer Console >> File >> New >> Lightning Component

dropdownCmp.cmp [Lightning Component]

  1.   <aura:component controller="dropdownCmpCtrl" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
  2.     <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> 
  3.     <aura:attribute name="statusListItems" type="string[]"/>
  4.     <aura:attribute name="targetVal" type="string"/>
  5.     <aura:attribute name="isMarried" type="string"/>
  6.  
  7.     <div class="slds slds-p-around--medium">
  8.         <div class="slds-grid slds-wrap"> 
  9.             <div class="slds-p-horizontal--medium slds-col slds-size_6-of-12 slds-m-bottom--medium">
  10.                 <div class="slds-form-element">
  11.                     <label class="slds-form-element__label">Target vs Actuals</label>
  12.                     <div class="slds-form-element__controller">
  13.                         <ui:inputSelect class="slds-select" aura:id="targetId" change="{!c.changeTarget}" value="{!v.targetVal}">
  14.                             <ui:inputSelectOption text="--None--"/>
  15.                             <aura:iteration items="{!v.statusListItems}" var="statusVar">
  16.                                 <ui:inputSelectOption text="{!statusVar}"/>
  17.                             </aura:iteration>
  18.                         </ui:inputSelect>
  19.                     </div>
  20.                 </div>
  21.             </div>
  22.             <div class="slds-col slds-size_6-of-12 slds-p-horizontal--small slds-m-bottom--small"> 
  23.                 <div class="slds-grid slds-wrap">
  24.                     <div class="slds-col slds-size_6-of-12">
  25.                         <div class="slds-form-element slds-is-required">
  26.                             <label class="slds-form-element__label">Is Married?</label>
  27.                             <div class="slds-form-element__controller">
  28.                                 <div class="slds-grid slds-wrap slds-m-top--x-small">                                                                
  29.                                     <label class="slds-radio">
  30.                                         <input type="radio" id="yesOption" class="slds-m-right--medium" name="isMarried" value="Yes" onclick="{!c.setMarriedVal}"/> 
  31.                                         <span class="slds-radio--faux"></span>
  32.                                         <span class="slds-form-element__label"> Yes</span>
  33.                                     </label>
  34.  
  35.                                     <label class="slds-radio">
  36.                                         <input type="radio" id="noOption"  name="isMarried" value="No" onclick="{!c.setMarriedVal}"/> 
  37.                                         <span class="slds-radio--faux"></span>
  38.                                         <span class="slds-form-element__label"> No</span>
  39.                                     </label>                                                                        
  40.                                 </div>
  41.                             </div>                                                                
  42.                         </div>
  43.                     </div>
  44.                     <div class="slds-col slds-size_6-of-12">
  45.                        <aura:if isTrue="{!v.isMarried == 'Yes'}">  
  46.                         <div  class="slds-form-element slds-is-required slds-m-top--small">
  47.                             <label class="slds-form-element__label">Spouse Name</label>
  48.                             <ui:inputText class="slds-input" aura:id="spouseName" />
  49.                         </div> 
  50.                       </aura:if>      
  51.                     </div>                                                         
  52.                 </div>
  53.             </div>
  54.  
  55.         </div>  
  56.         <aura:if isTrue="{!or(v.targetVal == 'Sales Target', v.targetVal == 'Score Value')}">  
  57.         <div class="slds-grid slds-wrap">
  58.             <div class="slds-p-horizontal--medium slds-col slds-size_6-of-12 slds-m-bottom--medium">
  59.                 <div class="slds-form-element">
  60.                     <label class="slds-form-element__label">Name</label>
  61.                     <div class="slds-form-element__controller">
  62.                         <ui:inputText class="slds-input" value="" aura:id="userName"/>
  63.                     </div>
  64.                 </div>
  65.             </div>
  66.  
  67.             <div class="slds-p-horizontal--medium slds-col slds-size_6-of-12 slds-m-bottom--medium">
  68.                 <div class="slds-form-element">
  69.                     <label class="slds-form-element__label">Designation</label>
  70.                     <div class="slds-form-element__controller">
  71.                         <ui:inputText class="slds-input" value="" aura:id="designation"/>
  72.                     </div>
  73.                 </div>
  74.             </div>
  75.         </div>
  76.        </aura:if>      
  77.  
  78.        <aura:if isTrue="{!or(v.targetVal == 'Achievement %', v.targetVal == 'Collections Target')}">    
  79.         <div class="slds-grid slds-wrap"> 
  80.             <div class="slds-p-horizontal--medium slds-col slds-size_6-of-12 slds-m-bottom--medium">
  81.                 <div class="slds-form-element">
  82.                     <label class="slds-form-element__label">Employee Code</label>
  83.                     <div class="slds-form-element__controller">
  84.                         <ui:inputText class="slds-input" value="" aura:id="employeeCode"/>
  85.                     </div>
  86.                 </div>
  87.             </div>
  88.  
  89.             <div class="slds-p-horizontal--medium slds-col slds-size_6-of-12 slds-m-bottom--medium">
  90.                 <div class="slds-form-element">
  91.                     <label class="slds-form-element__label">Annual Salary</label>
  92.                     <div class="slds-form-element__controller">
  93.                         <ui:inputText class="slds-input" value="" aura:id="annual"/>
  94.                     </div>
  95.                 </div>
  96.             </div>
  97.         </div> 
  98.      </aura:if>   
  99.  
  100.  <br/><br/>
  101.    <!--Start RelatedTopics Section-->
  102. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  103.  
  104.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click  <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
  105.  
  106.             <br/><br/>
  107.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/07/tickMarkIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like →</span> </strong></p>
  108.             <div style="display:block; overflow:hidden;"> 
  109.                 <div style="width: 50%; float:left; display:inline-block">
  110.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  111.                         <li><a href="https://www.w3web.net/lwc-get-set-lightning-checkbox-value/" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
  112.                         <li><a href="https://www.w3web.net/display-account-related-contacts-in-lwc/" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
  113.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
  114.                         <li><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
  115.                         <li><a href="https://www.w3web.net/get-selected-radio-button-value-and-checked-default-in-lwc/" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
  116.                     </ul>
  117.             </div>
  118.  
  119.             <div style="width: 50%; float:left; display:inline-block">
  120.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  121.                         <li><a href="https://www.w3web.net/display-account-related-contacts-lwc/" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
  122.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
  123.                         <li><a href="https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
  124.                         <li><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
  125.                         <li><a href="https://www.w3web.net/update-parent-object-from-child/" target="_blank" rel="noopener noreferrer">update parent field from child using apex trigger</a></li>
  126.                     </ul>
  127.                 </div>
  128.                <div style="clear:both;"></div> 
  129.                <br/>
  130.                 <div class="youtubeIcon">
  131.                     <a href="https://www.youtube.com/channel/UCW62gTen2zniILj9xE6LmOg" target="_blank" rel="noopener noreferrer"><img src="https://www.w3web.net/wp-content/uploads/2021/11/youtubeIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
  132.                 </div>
  133.     </div>
  134.  
  135. </div>
  136.  
  137.   <!--End RelatedTopics Section-->
  138.  
  139.     </div>
  140.  
  141. </aura:component>

JavaScript helper function in Salesforce by w3web.net

Create Component JavaScript Controller

Step 3:- Create Lightning Component : dropdownCmpController.js

From Developer Console >> File >> New >> Lightning Component >> JavaScript Controller

dropdownCmpController.js [JavaScript Controller]

  1.    ({
  2. 	doInit : function(component, event, helper) {
  3. 		helper.statusListItemsHelper(component);
  4. 	},
  5.  
  6.  
  7.     changeTarget:function(component, event, helper){
  8.         var targetVal = component.find('targetId').get('v.value');
  9.         //alert('targetVal ' + targetVal);
  10.         component.set('v.targetVal}',targetVal);
  11.     },
  12.  
  13.  
  14.     setMarriedVal: function(component,event) {
  15.         var val = event.currentTarget.value;
  16.         //alert(val);       
  17.         component.set("v.isMarried",val);
  18.     },
  19.  
  20.  
  21. })

Create Component JavaScript Helper

Step 4:- Create Lightning Component : dropdownCmpHelper.js

From Developer Console >> File >> New >> Lightning Component >> JavaScript Helper

dropdownCmpHelper.js [JavaScript Helper]

  1.   ({
  2. 	statusListItemsHelper : function(component, event, helper) {
  3. 		var action = component.get('c.pickList');
  4.         action.setParams({"obj":"scoreCard__c", "str":"targetVSActuals__c"});
  5.  
  6.         action.setCallback(this, function(response){
  7.             var state = response.getState();              
  8.             if(state == "SUCCESS"){
  9.                 var result = response.getReturnValue();
  10.                 component.set('v.statusListItems',result);
  11.             }
  12.         });
  13.         $A.enqueueAction(action);
  14. 	},
  15. })

Create Apex Class Controller

Step 5:- Create Apex Class : dropdownCmpCtrl.apxc

From Developer Console >> File >> New >> Apex Class

dropdownCmpCtrl.apxc [Apex Class Controller]

  1.     public class dropdownCmpCtrl {
  2.  
  3.     @AuraEnabled
  4.     public static List<String> pickList(String obj, String str) { 
  5.  
  6.          List<String> regList = NEW List<String>(); 
  7.             Schema.DescribeFieldResult plistvalues = Schema.getGlobalDescribe().get(obj).getDescribe().fields.getMap().get(str).getDescribe();
  8.             FOR(PicklistEntry ent:plistvalues.getpicklistvalues())     {
  9.                 regList.add(ent.getLabel());
  10.             }
  11.              RETURN regList;
  12.     }
  13.  
  14.  
  15. }

display picklist and radio values in lightning component -- w3web.net

Further post that would you like to learn in Salesforce

 

 

FAQ (Frequently Asked Questions)

How do I use dynamic forms in Salesforce?

When can I get Salesforce Dynamic Forms? Simply go to the Lightning record page of a custom object and select the “Highlights Panel” or the “Record Detail” component, then you'll see the option to “Upgrade Now” and can choose between migrating an existing page or starting from scratch.

What is restricted picklist in Salesforce?

Restricted picklists keep users from adding new values (either through the API or other apps). This restriction is useful for keeping your data consistent.

What is difference between dynamic and page layout?

An instant upgrade from page layouts: Place fields and sections wherever you want. Dynamic layouts: Use visibility rules to show and hide fields and sections. Simpler layout management: Manage the fields and sections on your pages in the Lightning App Builder without touching the page layout editor.

Related Topics | You May Also Like

 
  

Our Free Courses →

👉 Get Free Course →

📌 Salesforce Administrators

📌 Salesforce Lightning Flow Builder

📌 Salesforce Record Trigger Flow Builder

👉 Get Free Course →

📌 Aura Lightning Framework

📌 Lightning Web Component (LWC)

📌 Rest APIs Integration




Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment