Tuesday, September 19, 2017

[Salesforce / Lightning] Trigger automatic Lightning Quick Action popup close

Few days ago my #AwesomeAdmin buddy Tom Blamire asked me:

"Do you know if I can automatically close a Quick Action popup window after triggering an action that does not require a UI (like downloading something from a Visualforce page)?"

The flow was simple as he asked me: click on a quick action on a standard layout page (with Lightning Experience enabled), trigger something (that can be a call to a Visualforce page or simply a backend elaboration from Apex) and close automatically the popup.

This is the solution: in this case the setTimeout() call was necessary because you need to get a bit "asynchronous", but if you make an Apex controller callback, you don't need it.

Thanks to Salesforce Lightning framework it is easy as it seem:

<aura:component implements="force:lightningQuickAction,force:hasRecordId">
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
Loading data, please wait. . .
</aura:component>
view raw quickAction.cmp hosted with ❤ by GitHub
({
doInit : function(component, event, helper) {
window.location.href="/apex/backgroundPage?id="+component.get("v.recordId");
setTimeout(function(){
$A.get("e.force:closeQuickAction").fire();
}, 1000);
}
})


No comments:

Post a Comment