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

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:

Lightning Aura Component:

Component:

<aura:component implements=”force:hasRecordId,force:lightningQuickActionWithoutHeader” controller=”Sample” >  
      
    <div class=”slds-box slds-theme_default”>   
        <ui:button aura:id=”mybtn” class=”slds-button slds-button–brand slds-size–1-of-1″ label=”Testing” press=”{!c.onclick}” />  
    </div>  
      
</aura:component>  

Component Controller:
({      
      
    onclick : function(component, event, helper) {  
          
        var action = component.get( “c.firstMethod” );  
        action.setCallback(this, function(response){  
            var state = response.getState();  
            if (state === “SUCCESS”) {  
                  
                alert( response.getReturnValue() );  
                $A.get( “e.force:closeQuickAction” ).fire();  
                $A.get( “e.force:refreshView” ).fire();  
                  
            }  
        });  
        $A.enqueueAction(action);  
          
    }  
      
})  

Apex Class:
public class Sample {  
  
    @AuraEnabled  
    public static String firstMethod() {  
        return ‘Success’;  
    }  
  
}  


Output:


Leave a Reply