Lightning aura:handler change method to Call Multiple Apex Methods for different type of custom object uses of selected radio button value in aura component controller Salesforce | how to display multiple objects from selected radio button in lightning component Salesforce

2,437 views

Hey guys, today in this post we are going to learn about How to lightning aura:handler change method to Call Multiple Apex Methods for different type of custom object uses of change radio button value in aura component controller Salesforce.

aura:handler change method event is fired when an attribute value changes. Handle this event using the aura:handler tag. A component can have multiple aura:handler tags to detect changes to different attribute values. To more details about aura:handler change method in Salesforce click Here.


Real time scenarios:- Create multiple custom object and fetch the records by selected radio button value uses of aura:handler change method in lightning component controller.

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?

 

Files we used to Call Multiple Apex Methods in aura component controller in Salesforce

customCredentialCmp.cmp Lightning Component It is used for create a table for Iterate the list of custom object records on lightning component
customCredentialCmpController.js JavaScript Controller It is hold Javascript handleChangeAction and setCredentialVal functionality to get the radio button selected value.
customCredentialCmpHelper.js JavaScript Controller Helper It is hold for Javascript Helper Function to get multiple objects values from apex method.
customCredentialCtrl.apxc Apex Controller It is used for get List of multiple objects records from Apex Class Method
customCredentialCmpApp.app Lightning Application It is used for call the component and preview on browser.
List of Custom Object:- Custom_Credential__c, HDFC_Credential__c, IDBI_Credential__c Fields are same for all of three custom objects:- Name, API_Endpoint__c, ClientId__c, Client_Secret__c,

Final Output

display multiple objects from selected radio button -- w3web.net

 

You can download file directly from github by Click Here.

 

Other related post that would you like to learn in Salesforce

  

  • Find the below steps

Create Lightning Component

Step 1:- Create Lightning Component : customCredentialCmp.cmp

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

customCredentialCmp.cmp [Lightning Component File]

  1.  <aura:component controller="customCredentialCtrl" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >    
  2.     <aura:attribute name="customCrdtlObj" type="Custom_Credential__c" default="{'sobjectType':'Custom_Credential__c'}"/>
  3.     <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>    
  4.     <aura:handler name="change" value="{!v.landerVal}" action="{!c.handleChangeAction}"/>  
  5.     <aura:attribute name="landerVal" type="string" default=""/>
  6.     <aura:attribute name="manageVal" type="string" default=""/>
  7.     <aura:attribute name="customCrdtlList" type="List"/>
  8.     <aura:attribute name="hdfcCrdtlList" type="List"/>
  9.     <aura:attribute name="idbiCrdtlList" type="List"/>
  10.     <aura:attribute name="landerPickListItems" type="Custom_Credential__c[]"/>
  11.     <aura:attribute name="managePickListItems" type="Custom_Credential__c[]"/>
  12.     <aura:attribute name="targetLanderVal" type="string"/>
  13.     <aura:attribute name="targetManageVal" type="string"/>
  14.     <aura:attribute name="customCrdtlCheck" type="boolean" default="false"/>
  15.     <aura:attribute name="isCredential" type="string"/>
  16.  
  17.     <lightning:card> 
  18.         <div class="slds slds-p-around_medium">
  19.  
  20.             <div class="slds-grid slds-wrap">
  21.                     <div class="slds-col slds-size_12-of-12">
  22.                         <div class="slds-form-element slds-is-required">
  23.                             <label class="slds-form-element__label"><b>Credential Master</b></label>
  24.                             <div class="slds-form-element__controller">
  25.                                 <div class="slds-grid slds-wrap slds-m-top--x-small">                                                                
  26.                                     <label class="slds-radio">
  27.                                         <input type="radio" id="isCustomCredential" class="slds-m-right--medium" name="isCustomCredential" value="Custom Credential" onclick="{!c.setCredentialVal}"/> 
  28.                                         <span class="slds-radio--faux"></span>
  29.                                         <span class="slds-form-element__label"> Custom Credential</span>
  30.                                     </label>
  31.  
  32.                                     <label class="slds-radio">
  33.                                         <input type="radio" id="isHdfcCredential"  name="isCustomCredential" value="HDFC Credential" onclick="{!c.setCredentialVal}"/> 
  34.                                         <span class="slds-radio--faux"></span>
  35.                                         <span class="slds-form-element__label"> HDFC Credential</span>
  36.                                     </label>     
  37.  
  38.                                     <label class="slds-radio">
  39.                                         <input type="radio" id="isIdbiCredential"  name="isCustomCredential" value="IDBI Credential" onclick="{!c.setCredentialVal}"/> 
  40.                                         <span class="slds-radio--faux"></span>
  41.                                         <span class="slds-form-element__label"> IDBI Credential</span>
  42.                                     </label>
  43.                                 </div>
  44.                             </div>                                                                
  45.                         </div>
  46.                     </div>
  47.  
  48.                 </div>
  49.  
  50.             <div class="slds-hide">handleChange#### - {!v.handleChange}-- landerVal:- {!v.landerVal}</div><br/><br/>
  51.             <div class="slds-grid slds-wrap">
  52.                 <div class="slds-p-horizontal--medium slds-col slds-size_6-of-12 slds-m-bottom--medium">
  53.                     <div class="slds-form-element">
  54.                         <label class="slds-form-element__label">Landers <!--:- {!v.targetLanderVal}--></label>
  55.                         <div class="slds-form-element__controller">
  56.                             <ui:inputSelect class="slds-select" aura:id="landersId" change="{!c.changeTarget}" value="{!v.targetLanderVal}">
  57.                                 <ui:inputSelectOption text="--None--"/>
  58.                                 <aura:iteration items="{!v.landerPickListItems}" var="landerItem">
  59.                                     <ui:inputSelectOption text="{!landerItem}"/>
  60.                                 </aura:iteration>
  61.                             </ui:inputSelect>
  62.                         </div>
  63.                     </div>
  64.                 </div>
  65.  
  66.                 <div class="slds-p-horizontal--medium slds-col slds-size_6-of-12 slds-m-bottom--medium">
  67.                     <div class="slds-form-element slds-hide">
  68.                         <label class="slds-form-element__label">Landers Manage:- {!v.targetManageVal}</label>
  69.                         <div class="slds-form-element__controller">
  70.                             <ui:inputSelect class="slds-select" aura:id="manageId" change="{!c.changeManage}" value="{!v.targetManageVal}">
  71.                                 <ui:inputSelectOption text="--None--"/>
  72.                                 <aura:iteration items="{!v.managePickListItems}" var="manageItem">
  73.                                     <ui:inputSelectOption text="{!manageItem}"/>
  74.                                 </aura:iteration>
  75.                             </ui:inputSelect>
  76.                         </div>
  77.                     </div>
  78.                 </div>
  79.  
  80.             </div>
  81.  
  82.  
  83.             <aura:if isTrue="{!v.landerVal == 'Custom Credential'}">
  84.                 <div class="slds-section__title-action slds-p-around--small slds-m-bottom--medium">
  85.                     <h2><strong>Custom Credential</strong></h2>
  86.                 </div>
  87.                 <table class="slds-table slds-table_bordered slds-table_col-bordered" style="border:1px #ddd solid;">
  88.                     <thead>
  89.                         <tr>
  90.                             <th>Credential Name</th>
  91.                             <th>Endpoint</th>
  92.                             <th>Client Secret</th>
  93.                             <th>Client Id</th>
  94.                         </tr>                   
  95.                     </thead>
  96.                     <tbody>
  97.                         <aura:iteration items="{!v.customCrdtlList}" var="item" indexVar="index">
  98.                             <tr id="{!index}">
  99.                                 <td>{!item.Name}</td>
  100.                                 <td><div class="slds-grid slds-has-flexi-truncate" style="width:75px"><span class="slds-truncate" title="{!item.API_Endpoint__c}">{!item.API_Endpoint__c}</span></div></td>
  101.                                 <td>{!item.ClientId__c}</td>
  102.                                 <td>{!item.Client_Secret__c}</td>
  103.                             </tr>
  104.                         </aura:iteration>                   
  105.                     </tbody>
  106.                 </table>
  107.             </aura:if>
  108.  
  109.  
  110.             <aura:if isTrue="{!v.landerVal == 'HDFC Credential'}">
  111.                 <div class="slds-section__title-action slds-p-around--small slds-m-bottom--medium">
  112.                     <h2><strong>HDFC Credential</strong></h2>
  113.                 </div>
  114.                 <table class="slds-table slds-table_bordered slds-table_col-bordered" style="border:1px #ddd solid;">
  115.                     <thead>
  116.                         <tr>
  117.                             <th>Credential Name</th>
  118.                             <th>Endpoint</th>
  119.                             <th>Client Secret</th>
  120.                             <th>Client Id</th>
  121.                         </tr>                   
  122.                     </thead>
  123.                     <tbody>
  124.                         <aura:iteration items="{!v.hdfcCrdtlList}" var="item" indexVar="index">
  125.                             <tr id="{!index}">
  126.                                 <td>{!item.Name}</td>
  127.                                 <td><div class="slds-grid slds-has-flexi-truncate" style="width:75px"><span class="slds-truncate" title="{!item.API_Endpoint__c}">{!item.API_Endpoint__c}</span></div></td>
  128.                                 <td>{!item.ClientId__c}</td>
  129.                                 <td>{!item.Client_Secret__c}</td>
  130.                             </tr>
  131.                         </aura:iteration>                   
  132.                     </tbody>
  133.                 </table>
  134.             </aura:if>
  135.  
  136.  
  137.             <aura:if isTrue="{!v.landerVal == 'IDBI Credential'}">
  138.                 <div class="slds-section__title-action slds-p-around--small slds-m-bottom--medium">
  139.                     <h2><strong>IDBI Credential</strong></h2>
  140.                 </div>
  141.                 <table class="slds-table slds-table_bordered slds-table_col-bordered" style="border:1px #ddd solid;">
  142.                     <thead>
  143.                         <tr>
  144.                             <th>Credential Name</th>
  145.                             <th>Endpoint</th>
  146.                             <th>Client Secret</th>
  147.                             <th>Client Id</th>
  148.                         </tr>                   
  149.                     </thead>
  150.                     <tbody>
  151.                         <aura:iteration items="{!v.idbiCrdtlList}" var="item" indexVar="index">
  152.                             <tr id="{!index}">
  153.                                 <td>{!item.Name}</td>
  154.                                 <td><div class="slds-grid slds-has-flexi-truncate" style="width:75px"><span class="slds-truncate" title="{!item.API_Endpoint__c}">{!item.API_Endpoint__c}</span></div></td>
  155.                                 <td>{!item.ClientId__c}</td>
  156.                                 <td>{!item.Client_Secret__c}</td>
  157.                             </tr>
  158.                         </aura:iteration>                   
  159.                     </tbody>
  160.                 </table>
  161.             </aura:if>
  162.             <br/><br/>
  163.     <p><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong> <span style="font-size:15px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span> <a href="https://www.w3web.net/" target="_blank" style="text-decoration:none;" rel="noopener noreferrer">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click  <span style="color:#ff8000; font-size:18px;">Here..</span></a></strong></p>
  164.  
  165.  
  166. <br/><br/><br/>
  167.   <!--Start RelatedTopics Section-->
  168. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  169.  
  170.             <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>
  171.  
  172.             <br/><br/>
  173.             <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>
  174.             <div style="display:block; overflow:hidden;"> 
  175.                 <div style="width: 50%; float:left; display:inline-block">
  176.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  177.                         <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>
  178.                         <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>
  179.                         <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>
  180.                         <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>
  181.                         <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>
  182.                     </ul>
  183.             </div>
  184.  
  185.             <div style="width: 50%; float:left; display:inline-block">
  186.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  187.                         <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>
  188.                         <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>
  189.                         <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>
  190.                         <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>
  191.                         <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>
  192.                     </ul>
  193.                 </div>
  194.                <div style="clear:both;"></div> 
  195.                <br/>
  196.                 <div class="youtubeIcon">
  197.                     <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>
  198.                 </div>
  199.     </div>
  200.  
  201. </div>
  202.  
  203.   <!--End RelatedTopics Section-->
  204.  
  205.  
  206.         </div>
  207.     </lightning:card>    
  208. </aura:component>

Create JavaScript Controller

Step 2:- Create Lightning Component : customCredentialCmpController.js

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

customCredentialCmpController.js [JavaScript Controller]

  1.    ({
  2. 	doInit : function(component, event, helper) {	 
  3.  
  4. 	},
  5.  
  6.  
  7.  
  8.     handleChangeAction:function(component, event, helper){        
  9.         var landerChangeVal = component.get('v.landerVal');
  10.         //alert('landerChangeVal ' + landerChangeVal);
  11.         if(landerChangeVal == "Custom Credential"){           
  12.             helper.customCrdtlHelper(component);	
  13.         }
  14.         if(landerChangeVal == "HDFC Credential"){           
  15.             helper.hdfcCrdtlHelper(component);	
  16.         }
  17.         if(landerChangeVal == "IDBI Credential"){           
  18.             helper.idbiCrdtlHelper(component);	
  19.         }
  20.  
  21.     },
  22.  
  23.      setCredentialVal: function(component,event) {
  24.         var val = event.currentTarget.value;
  25.         //alert(val);       
  26.         component.set("v.isCredential",val);
  27.         component.set('v.targetLanderVal',val);
  28.         component.set('v.landerVal',val);
  29.     },
  30.  
  31.  
  32. })

Create JavaScript Helper

Step 3:- Create Lightning Component : customCredentialCmpHelper.js

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

customCredentialCmpHelper.js [JavaScript Helper File]

  1.    ({
  2. 	customCrdtlHelper : function(component, event, helper) {
  3. 	  	var action = component.get("c.getCustCredential");        
  4.         action.setCallback(this, function(response){
  5.             var state = response.getState();            
  6.             if(state == "SUCCESS"){
  7.               var result = response.getReturnValue();
  8.                // alert('result ' + JSON.stringify(result));
  9.                component.set('v.customCrdtlList', result);
  10.             }
  11.         });        
  12.         $A.enqueueAction(action);
  13. 	},
  14.  
  15.     hdfcCrdtlHelper : function(component, event, helper) {
  16. 	  	var action = component.get("c.getHdfcCredential");        
  17.         action.setCallback(this, function(response){
  18.             var state = response.getState();            
  19.             if(state == "SUCCESS"){
  20.               var result = response.getReturnValue();
  21.                // alert('result ' + JSON.stringify(result));
  22.                component.set('v.hdfcCrdtlList', result);
  23.             }
  24.         });        
  25.         $A.enqueueAction(action);
  26. 	},
  27.  
  28.     idbiCrdtlHelper : function(component, event, helper) {
  29. 	  	var action = component.get("c.getIdbiCredential");        
  30.         action.setCallback(this, function(response){
  31.             var state = response.getState();            
  32.             if(state == "SUCCESS"){
  33.               var result = response.getReturnValue();
  34.                // alert('result ' + JSON.stringify(result));
  35.                component.set('v.idbiCrdtlList', result);
  36.             }
  37.         });        
  38.         $A.enqueueAction(action);
  39. 	},
  40.  
  41. })

Create Apex Class Controller

Step 4:- Create Apex Class : customCredentialCtrl.apxc

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

customCredentialCtrl.apxc [Apex Class Controller]

  1.   public class customCredentialCtrl {
  2.  
  3.   @AuraEnabled
  4.     public static List getCustCredential(){
  5.         List custCredentialList = [SELECT Id, Name, API_Endpoint__c, ClientId__c, Client_Secret__c, Credential_Landers__c, Landers_Manage__c, HDFC_Credential__c, IDBI_Credential__c, HDFC_Credential__r.Name, IDBI_Credential__r.Name FROM Custom_Credential__c WHERE Name !=NULL];
  6.         system.debug('custCredentialList ' + custCredentialList);
  7.         RETURN custCredentialList;
  8.     }
  9.  
  10.     @AuraEnabled
  11.     public static List getHdfcCredential(){
  12.         List hdfcCredentialList = [SELECT Id, Name, API_Endpoint__c, ClientId__c, Client_Secret__c  FROM HDFC_Credential__c WHERE Name !=NULL];
  13.         system.debug('hdfcCredentialList ' + hdfcCredentialList);
  14.         RETURN hdfcCredentialList;
  15.     }
  16.  
  17.  
  18.     @AuraEnabled
  19.     public static List getIdbiCredential(){
  20.         List idbiCredentialList = [SELECT Id, Name, API_Endpoint__c, ClientId__c, Client_Secret__c  FROM IDBI_Credential__c WHERE Name !=NULL];
  21.         system.debug('idbiCredentialList ' + idbiCredentialList);
  22.         RETURN idbiCredentialList;
  23.     }
  24.  
  25.  
  26. }

Create Lightning Application

Step 5:- Create Lightning Application : customCredentialCmpApp.app

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

customCredentialCmpApp.app [Component Application File]

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

Further post that would you like to learn in Salesforce

 

 

FAQ (Frequently Asked Questions)

What is radio button in Salesforce lightning?

A lightning:radioGroup component represents a group of radio buttons that permit only one button to be selected at a time.

What is radio button what is its use?

Radio buttons allow the user to select one option from a set.

What is required to make a group of radio buttons?

To group radio buttons they must all have the same name value. This allows only one to be selected at a time and applies required to the whole group.

What is change handler in lightning?

Configure a component to automatically invoke a change handler, which is a client-side controller action, when a value in one of the component's attributes changes. When the value changes, the valueChange. evt event is automatically fired.

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