June 30, 2019

How to close the quick action popup and refresh the page from custom Salesforce Lightning Component?

Use the below methods to close the quick action popup and refresh the page from custom Salesforce Lightning Component.

                $A.get("e.force:closeQuickAction").fire();

                $A.get('e.force:refreshView').fire();

Sample code:

Component:


  1. <aura:component implements="force:hasRecordId,force:lightningQuickActionWithoutHeader" controller="Sample" >  
  2.       
  3.     <div class="slds-box slds-theme_default">   
  4.         <ui:button aura:id="mybtn" class="slds-button slds-button--brand slds-size--1-of-1" label="Testing" press="{!c.onclick}" />  
  5.     </div>  
  6.       
  7. </aura:component>  

Component Controller:


  1. ({      
  2.       
  3.     onclick : function(component, event, helper) {  
  4.           
  5.         var action = component.get( "c.firstMethod" );  
  6.         action.setCallback(this, function(response){  
  7.             var state = response.getState();  
  8.             if (state === "SUCCESS") {  
  9.                   
  10.                 alert( response.getReturnValue() );  
  11.                 $A.get("e.force:closeQuickAction").fire();  
  12.                 $A.get('e.force:refreshView').fire();  
  13.                   
  14.             }  
  15.         });  
  16.         $A.enqueueAction(action);  
  17.           
  18.     }  
  19.       
  20. })  

Apex Class:


  1. public class Sample {  
  2.   
  3.     @AuraEnabled  
  4.     public static String firstMethod() {  
  5.         return 'Success';  
  6.     }  
  7.   
  8. }  

Output:





No comments:

Post a Comment