1

Created a aura component and have overrided this component with NEW standard button . On click of save, record gets created and redirect happens successfully. The problem is, while clicking the cancel button the page is not redirecting back to the standard list view page.

Below is my sample code. I have also tried all the various ways of destroying the component and redirecting to the list view but have not been sucessfull in redirecting back.

Any suggestions in this regard is highly appreciated.

var createAcountContactEvent = $A.get("e.force:createRecord");
                createAcountContactEvent.setParams({
                    "entityApiName": "Pipeline__c",
                    recordTypeId: recordTypeId,
                    "navigationLocation":"LOOKUP",
                    "panelOnDestroyCallback": function(event) {
                        var urlEvent = $A.get("e.force:navigateToURL");                           
                            urlEvent.setParams({
                                "url": "/lightning/o/Pipeline__c/home", 
                                "isredirect":true
                            });
                            urlEvent.fire();
                    }
                });
                createAcountContactEvent.fire();

Thank you!!!

2
  • Did you try an absolute URL like: "panelOnDestroyCallback": function(event) { window.location.href = "google.com"; }
    – Ayub
    May 1, 2020 at 6:08
  • Thanks @Ayub for your insight. However, absolute url is also not working...Tried with all the possible ways
    – sfdc
    May 1, 2020 at 13:56

2 Answers 2

0

Found this sample code while referring to the following ideas

https://success.salesforce.com/ideaView?id=0873A0000003VnmQAE

https://success.salesforce.com/ideaView?id=0873A000000CSXWQA4

Unsure if this will help but you can try something like this

    ({
    handleNewEngagement : function(component, event, helper) {

        let currentUrl = decodeURIComponent(window.location.search.substring(1));
        let createRecordEvent = $A.get("e.force:createRecord");

        createRecordEvent.setParams({
            "entityApiName": "Opportunity",
            "defaultFieldValues": {
                'Name' : 'Save to auto-populate',
                'AccountId' : component.get("{!v.recordId}")
            },
            "panelOnDestroyCallback":function(event) {
                var navEvt = $A.get("e.force:navigateToSObject");
                navEvt.setParams({
                    "recordId": component.get("v.recordId"),
                    "isredirect":true
                });
                // navigate back to account only if opportunity create was cancelled
                decodeURIComponent(window.location.search.substring(1)) == currentUrl ? navEvt.fire() : console.log('nav to opportunity');
            }
        });
        createRecordEvent.fire();
    }
})

Also, Does panelOnDestroyCallback work for you?

Anudeep

1
  • Thank you @anudeep . i have tried the above code and have gone through the links as well... but no luck so far
    – sfdc
    May 1, 2020 at 17:29
0

panelOnDestroyCallback is not a documented solution and it has stopped working now after new upgrades.

Please vote for the below idea with similar problem. https://success.salesforce.com/ideaView?id=0873A000000CSXWQA4

You must log in to answer this question.

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