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.


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 }"/> 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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