function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
StunaiteStunaite 

Overriding New Action just runs first time when called from Related List

TesterContainer.cmp
<aura:component implements="lightning:actionOverride,lightning:hasPageReference"> 
    <!-- Handler of init to execute actions on loading -->
    <aura:handler 	name="init" 	value="this" action="{!c.doInit}"/>
    <!-- LWC to handle all logic; has to be wrapped on aura component which implements lightning:actionOverride
         It is commented to simplify the example and avoiding useless noise
    <c:lWC_NewContactOverriden>
    -->    
</aura:component>
TesterContainerController.js
({
    doInit : function(component, event, helper) {
        console.log('Start doInit');
        $A.get("e.force:closeQuickAction").fire();
    }
})

On contact override New Action with this component
Setup->Object Manager->Contact->Buttons Links and Actions ->New

 typeUser-added image

Attention: Skip record type selection page is Checked.

Please run this example on contact related list on account.
Open console on your browser developer tools.

Click on the New button to run the component as below:

User-added image

You will see on console the result of executing doInit. Console will show:
"Start doInit"

The screen will be blue cos there is no visual components on markup file TesterContainer.cmp.

Now navigate again to account page but DON'T RELOAD the page on browser. Just go back to the previous page, so the account page is shown again.

Press again on New button as before:

You will see on console that doInit() method doesn't run!

Can't find why, cos I was careful to close the component and it should be destroyed as:

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_jsapi_component_destroy.htm

Please help cos I'm waisting tons of time and I'm with no ideas.

Thanks in Advance!





 
Best Answer chosen by Stunaite
Alain CabonAlain Cabon
‘init’ event not always firing on Lightning component used as ‘New’ Action Override?
https://salesforce.stackexchange.com/questions/220210/init-event-not-always-firing-on-lightning-component-used-as-new-action-overr

 

All Answers

Alain CabonAlain Cabon
‘init’ event not always firing on Lightning component used as ‘New’ Action Override?
https://salesforce.stackexchange.com/questions/220210/init-event-not-always-firing-on-lightning-component-used-as-new-action-overr

 
This was selected as the best answer
StunaiteStunaite
Thanks Alain.

I've already had tried that and I found that the solution is:
 
    //This is a workaround for init not firing when component is invoked after first time 
    //First time init fires and pagereference doesn't
    //Next times pagereference fires so a refreshView forces component to run as First Time
    onPageReferenceCh: function(cmp, event, helper) {
        $A.get('e.force:refreshView').fire();
    }