How to create Quick Action button and add lightning component with custom loading spinner and autolaunch/navigate in Aura:Component Salesforce | Using Lightning Component for Quick Action Button and navigate to custom aura:component page uses of “e.force:navigateToComponent” property in lightning component Salesforce

5,440 views

Hey guys, today in this post we are going to learn about How to create Quick Action Button and add lightning component with custom loading spinner and autolaunch/navigate in Aura:Component Salesforce.

When used as actions, components that implement the force:lightningQuickAction interface display in a panel with standard action controls, such as a Cancel button. These components can display and implement their own controls in the body of the panel, but can’t affect the standard controls.

This interface is a marker interface. A marker interface is a signal to the component’s container to add the interface’s behavior to the component. You don’t need to implement any specific methods or attributes in your component, you simply add the interface name to the component’s implements attribute. To know more details about Lightning Quick Action, Click Here β†’

Why Should You Attend It?

🎯 If You Are Facing Any Of These 6 Challenges. This Masterclass Is For You.

  • 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 create Quick Action functionality in aura:component β†’

quickActionAura.cmp Lightning Component It is used to create Quick Action functionality in lightning component
quickActionAuraController.js JavaScript Controller It is hold Javascript doInit functionality in lightning component.
quickActionAuraHelper.js JavaScript Helper It is used to fetch the Contact and Opportunity records based on RecordId in lightning component.
quickActionSpinner.cmp Lightning Component It is used to display Loading Spinner in lightning component
quickActionSpinnerController.js JavaScript Controller It is hold Javascript doInit function in lightning component.
quickActionSpinnerHelper.js JavaScript Helper It is hold e.force:navigateToComponent property to navigate to custom aura:component page
quickActionAuraCtrl.apxc Apex Class Controller It is used for get SOQL query to retrieve Contact and Opportunity records based on RecordId

 

 

Final Output β†’

quick action with custom loading in lightning -- w3web.net

 

You can download file directly from github by Click Here.

 
 

 

Other related post that would you like to learn in Salesforce

 
quick action with custom loading in lightning -- w3web.net
 

  • Find the below steps β–Ύ

 

Create Lightning Component β†’

Step 1:- Create Lightning Component : quickActionAura.cmp

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

quickActionAura.cmp [Lightning Component File]

  1.    <aura:component controller="quickActionAuraCtrl"  implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction,force:hasRecordId" access="global" >
  2.     <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
  3.     <aura:attribute name="conObjList" type="list"/>
  4.     <aura:attribute name="opptyObjList" type="list"/>
  5.  
  6.     <lightning:card> 
  7.         <div class="slds-p-around_large">
  8.             <h2 class="slds-text-heading_medium"><lightning:icon iconName="custom:custom87" size="small"/> <strong style="color:#270086; font-size:16px; margin-right:5px;"> How to create lightning quick action in Aura Component [<a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer">View more articles β†’</a>]</strong></h2>
  9.             <br/>
  10.  
  11.             <aura:if isTrue="{!v.conlist.length!=0}">
  12.                 <table  class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_col-bordered" style="border:1px #ddd solid;">
  13.                     <caption><lightning:icon iconName="standard:contact" />
  14.                         Contacts:<b>({!v.conObjList.length})</b></caption>                    
  15.                     <thead>                     
  16.                         <tr>
  17.                             <th>Name</th>
  18.                             <th>FirstName</th>
  19.                             <th>LastName</th>
  20.                             <th>Email</th>               
  21.                             <th>Phone</th>              
  22.                         </tr>
  23.                     </thead>
  24.                     <tbody> 
  25.                         <aura:iteration items="{!v.conObjList}" var="Items">
  26.                             <tr>
  27.                                 <td>{!Items.Name}</td>
  28.                                 <td>{!Items.FirstName}</td>
  29.                                 <td>{!Items.LastName}</td>
  30.                                 <td>{!Items.Email}</td>
  31.                                 <td>{!Items.Phone}</td>
  32.                             </tr>
  33.                         </aura:iteration>
  34.                     </tbody>      
  35.                 </table>
  36.             </aura:if>
  37.  
  38.             <br/><br/><br/>
  39.             <aura:if isTrue="{!v.opptyObjList.length!=0}">
  40.                 <table  class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_col-bordered" style="border:1px #ddd solid;">
  41.  
  42.                     <caption><lightning:icon iconName="standard:opportunity" />
  43.                         Opportunities:<b>({!v.opptyObjList.length})</b></caption>
  44.  
  45.                     <thead>
  46.                         <tr>
  47.                             <th>Name</th>
  48.                             <th>Amount</th>
  49.                             <th>Account Name</th>
  50.                             <th>CloseDate</th>               
  51.                             <th>StageName</th>              
  52.                         </tr>
  53.                     </thead>
  54.  
  55.                     <tbody>
  56.                         <aura:iteration items="{!v.opptyObjList}" var="Items">
  57.                             <tr>
  58.                                 <td>{!Items.Name}</td>
  59.                                 <td>{!Items.Amount}</td>
  60.                                 <td>{!Items.Account.Name}</td>
  61.                                 <td>{!Items.CloseDate}</td>
  62.                                 <td>{!Items.StageName}</td>
  63.                             </tr>
  64.                         </aura:iteration>
  65.                     </tbody>
  66.  
  67.                 </table>
  68.             </aura:if>
  69.  
  70.         </div>
  71.     </lightning:card>   
  72.  
  73. </aura:component>

 

Create JavaScript Controller β†’

Step 2:- Create Lightning Component : quickActionAuraController.js

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

quickActionAuraController.js [JavaScript Controller]

  1.     ({
  2. 	doInit : function(component, event, helper)
  3.     {
  4.         helper.retrieveConRecord(component,event,helper);
  5.         helper.retrieveOpptRecords(component,event,helper);
  6.     },    
  7.  
  8. })

 

Create JavaScript Helper β†’

Step 3:- Create Lightning Component : quickActionAuraHelper.js

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

quickActionAuraHelper.js [JavaScript Helper File]

  1.    ({
  2.     retrieveConRecord : function(component,event,helper)
  3.     {
  4.         var action = component.get("c.conListItem");
  5.         action.setParams({
  6.             "accountId": component.get("v.recordId")
  7.         });
  8.         action.setCallback(this, function(response) {
  9.             var state = response.getState();
  10.             if(state === "SUCCESS")
  11.             {
  12.                 var result = response.getReturnValue();
  13.                 component.set("v.conObjList", result);
  14.             }
  15.             else
  16.             {
  17.                 console.log('Some error occurred due to fetching the data');
  18.             }
  19.  
  20.         });
  21.  
  22.         $A.enqueueAction(action);
  23.  
  24.     },
  25.  
  26.  
  27.     retrieveOpptRecords :function(component,event,helper)
  28.     {
  29.         var action = component.get("c.oppListItem");
  30.         action.setParams({
  31.             "accId": component.get("v.recordId")
  32.         });
  33.  
  34.         action.setCallback(this, function(response) {
  35.             var state = response.getState();
  36.             if(state === "SUCCESS")
  37.             {
  38.                 var result = response.getReturnValue();
  39.                 component.set("v.opptyObjList", result);
  40.  
  41.             } else {
  42.                 console.log('Some error occurred due to fetching the data');
  43.             }
  44.  
  45.         });
  46.  
  47.         $A.enqueueAction(action);
  48.  
  49.     }   
  50.  
  51. })

 

Create Lightning Component β†’

Step 4:- Create Lightning Component : quickActionSpinner.cmp

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

quickActionSpinner.cmp [Lightning Component File]

  1.    <aura:component controller="quickActionAuraCtrl" 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.     <div class="slds-form--stacked slds-p-around_medium slds-p-bottom--none">
  4.         Please wait loading page...
  5.     </div>
  6. </aura:component>

 

Create JavaScript Controller β†’

Step 5:- Create Lightning Component : quickActionSpinnerController.js

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

quickActionSpinnerController.js [JavaScript Controller]

  1.    ({
  2.     doInit:function(component,event,helper)
  3.     {
  4.         helper.quickActionHelper(component,event,helper);
  5.     },    
  6.  
  7. })

 

Create JavaScript Helper β†’

Step 6:- Create Lightning Component : quickActionSpinnerHelper.js

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

quickActionSpinnerHelper.js [JavaScript Helper File]

  1.   ({
  2.  
  3.     quickActionHelper : function(component, event, helper)
  4.     {
  5.         var evt = $A.get("e.force:navigateToComponent");
  6.         evt.setParams
  7.         ({
  8.             componentDef : "c:quickActionAura",
  9.             componentAttributes:
  10.             {
  11.                 recordId :component.get("v.recordId")
  12.             }
  13.         });
  14.         evt.fire();
  15.     },    
  16.  
  17. })

 

Create Apex Class Controller β†’

Step 7:- Create Apex Class : quickActionAuraCtrl.apxc

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

quickActionAuraCtrl.apxc [Apex Class Controller]

  1.     public class quickActionAuraCtrl {
  2.    @AuraEnabled
  3.  
  4.     public static List<Contact> conListItem(Id accountId)
  5.     {
  6.         List<Contact> conlist=[SELECT Id, Name, FirstName, LastName, Email, Phone, Description FROM Contact WHERE AccountId = :accountId];
  7.         System.debug('##length of contact ##'+conlist.size());
  8.         RETURN conlist;
  9.     }
  10.     @AuraEnabled
  11.     public static List<Opportunity> oppListItem(Id accId)
  12.     {
  13.         List<Opportunity> opplist=[SELECT Id, Name, Amount, AccountId, Account.Name, CloseDate, Description, StageName FROM Opportunity WHERE AccountId=:accId];
  14.         System.debug('## length of Opportunity ## '+opplist.size());
  15.         RETURN opplist;
  16.     }
  17. }

 
quick action with custom loading in lightning -- w3web.net
 

Further post that would you like to learn in Salesforce

 


 

FAQ (Frequently Asked Questions)

How do I add Aura components to quick action?

Go to Account >> Select a record >> Click on the actions dropdown >> Select your Quick Action/Lightning Action which have use Lightning Component.

How do you show quick action in lightning?

Select the page layout that you want to add the action to, and then click Edit. Add quick actions to the case page layout. Click Mobile & Lightning Actions. Drag the action into the Salesforce Mobile and Lightning Experience Actions section, and then place the action where you want it to appear.

How do you close quick action in Aura component?

To close a quick action panel, usually in response to completing or canceling the action, run $A. get('e. force:closeQuickAction'). fire();

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