0

I have created a page and showed a component on that page. I am opening that page in the lightning tab from lightning quick action. I want to call a apex method whenever user close that page either from browser close or from tab close. So to achieve above requirement is there any way?

enter image description here

Thanks in advance.

3

On top of my head you won't be able to call apex when the browser is closed in Native Salesforce. There is JS onunload method that you can try, but it might not always work according to W3Schools.

Note: Due to different browser settings, this onunload event may not always work as expected.

In Native SF when Tab or Subtab is closed you will be able to do that by subscribing to lightning:tabClosed

lightning:tabClosed is an application event that indicates a tab has been closed successfully. This event is supported in Lightning console apps only.

<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
    <lightning:workspaceAPI aura:id="workspace" />  
    <aura:handler event="lightning:tabClosed" action="{! c.onTabClosed }"/> 
</aura:component>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.