5

I am overriding a Custom Object's New and Edit Action with an Aura Component.

Inconsistent with Standard behavior the Aura Component is not rendering in a modal over the calling page but on new page.

How can I go back to the calling page when my Action finishes?

Currently, I am using window.history.back() which fixes the redirect issue but because of cache the newly created records are not visible.

2 Answers 2

2
+50

I found one workaround for this particular scenario, although not the most elegant one, it works just fine:

refresh : function(){
    window.setTimeout(
        $A.getCallback(function(){
            $A.get('e.force:refreshView').fire();
        }
    ), 500);
}

The refresh function call should happen after calling the lightning navigation service:

this.navigateToRecord(component);
this.refresh();

In my case, this takes me back to the page where the standard related list is and fires a refreshView event on it rerendering the list with the latest data.

2

I ran into the sam issues and solved them by resorting to a Visualforce wrapping my Aura component:

  1. Quick Action UI not rendered as modal -> fake modal look with stencil images
  2. Inconsistent Navigation behavior -> Redirect using more powerful Apex

enter image description here

Wrapper VF page

<apex:page standardController="Account" applyBodyTag="false" extensions="EditAccountCtrl" tabStyle="Account" recordSetVar="accounts">
    <apex:includeLightning />

    <body><div id="addHere" /></body>

    <apex:form >
        <apex:actionFunction action="{!redirectToList}" name="close" />
    </apex:form>
    
    <script>
        $Lightning.use("c:myApp", () => {
            const accountIds = {!serializedAccountIds};
            $Lightning.createComponent("c:editAccounts", {accountIds}, "addHere");
        });

        document.addEventListener("showToast", (event) => {
            sforce.one.showToast(event.detail);
        });

        document.addEventListener("close", () => close());
    </script>
    
    <style>
        body {
            background: url("https://res.cloudinary.com/hy4kyit2a/f_auto,fl_lossy,q_70/learn/modules/lightning_design_system/lightning-design-system3/images/9830e3e95f11941fe2d0f3a14230f714_unit3-listview-wireframe.png") no-repeat;
            background-size: cover;
        }
    </style>
</apex:page>

and a Controller class which is better able to redirect to the caller. In my case its a hardcoded list view but I think you can also find out what was the original page.

public with sharing class EditAccountCtrl {

    private Set<Id> accountIds = new Set<Id>();
    public String serializedAccountIds { get; private set; }


    // CONSTRUCTORS

    public EditAccountCtrl(ApexPages.StandardController ctrl) {
        accountIds = new Set<Id>{ ctrl.getId() };
        serializedAccountIds = JSON.serialize(accountIds);
    }


    // PUBLIC

    public PageReference redirectToList() {
        return new ApexPages.Action('{!List}').invoke();
    }
    ...
}
2
  • 2
    Thanks, @robert I have 2 concerns with this approach, 1. adding a VF layer will make things slow 2. How will the redirection back to a sub-tab which is not the default subtab work. (if I initiate the quick action from a related list which is in a subtab, the redirection will always open the default subtab) Commented Sep 13, 2021 at 9:39
  • You are right on both. Maybe then this is not a solution for your issue. Commented Sep 13, 2021 at 9:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .