[SalesForce] Lightning force:createRecord capture redirect after save

Is there a way to use force:createRecord but capture the redirect to the newly created record page that occurs after saving the record? Finally, prevent the redirect from completing?

createRecord : function (component) {
    var createRecordEvent = $A.get("e.force:createRecord");
    createRecordEvent.setParams({
        "entityApiName": "Event__c"
    });
    createRecordEvent.fire();
} 

Best Answer

So instead of hacking the redirect with window.location.hash, you can use the following navigation method in the "panelOnDestroyCallback".

"panelOnDestroyCallback": function(event) {
                $A.get("e.force:navigateToSObject").setParams({
                    recordId: component.get("v.recordId"),
                    slideDevName: "detail"
                }).fire();
            }

The page will navigate to the new record and then back so it is not the smoothest transition but it does work.

EDIT

Just add "navigationLocation": "RELATED_LIST" to the list of params and you will stay on the page after saving.

Related Topic