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
Khushmeet KaurKhushmeet Kaur 

My question is that is there any way i can take the user back to account detail page if he/she closes the modal dialog or click cancel

I have overriden my standard newContact page with a custom lightning component bundle. The reason i did this is to avoid  standard salesforce fields like account phone getting auto populated when creating a contact through Account related list. 

I utilized force:createRecord event and have resolved almost all of the issues except for only 1 which i am stuck and need to get it resolved.

Problem: The problem is that in my component i am retrieveing accountId and recordTypeID. When i click on an account i ended up on the detail page. Now when i click new contact from account detail related list, it invokes my lightning component which basically fires force:Createrecord event. Since i came from the account detail page, my parent window should be account detail page also but it is not. It basically hovers over to an empty 'Contacts'  tab. This is because the window URL has changed.

Original URL before creating new contact from account detail page:-
https://*.force.com/one/one.app#/sObject/001f400000AdMNOAA3/view

After clicking new contact :-
https://*.force.com/one/one.app#/sObject/Contact/new?recordTypeId=012f4000000DzRj&additionalParams=accid%3D001f400000AdMNO%26

My question is that is there any way i can take the user back to account detail page if he/she closes the modal dialog or click cancel ? Please find my small test code below

ContactComponent.cmp
<aura:component implements="force:lightningQuickAction,lightning:actionOverride,force:hasRecordId,flexipage:availableForAllPageTypes,force:appHostable" access="global">
    <aura:handler name="init" value="{!this}" action="{!c.init}" />
    <aura:attribute name="accid" type="Id" />
    <aura:attribute name="recordTypeId" type="Id" />
</aura:component>

ContactComponentController.js
({
    init : function(component, event, helper) {
        console.log('insideinit');
                var createAcountContactEvent = $A.get("e.force:createRecord");
                console.log('Account ID after action is ' + accId);
                createAcountContactEvent.setParams({
                    "entityApiName": "Contact",
                    "defaultFieldValues": {
                        'Phone' : ''
                    }
                });
                createAcountContactEvent.fire(); 
    }
})
Shubham_KumarShubham_Kumar
Hi Khushmeet
Yes you can do this becausee close icon and cancel both are buttons as you can see here (https://lightningdesignsystem.com/components/modals/) in the documentation. I had somewhat similar situation a while ago, i actually removed the close and cancel using the below code and then added a custom cancel button to navigate to the detail page.
 .modal-footer.slds-modal__footer{
        display:none !important;
        }
        .slds-modal__close{
        display:none !important;
        }
One more thng that you have to keep in mind that Modals get closed when you press Esc key too,So you will have to handle the onKeyPress Event too.
Do let me know if you have any further queries.
Please mark this as the best solution if this helps you.

Regards
Shubham Kumar