[SalesForce] LWC – Redirecting “Save” button destination when using new “standard__objectPage” modal in NavigationMixin

I have created a "New" button in a component on a record page.

<div slot="actions">
    <lightning-button label="New" slot="actions" onclick={navigateToNew}></lightning-button>
</div>

The button points to a NavigationMixin that opens a popup for creating a new child-detail record for the record they are currently looking at:

navigateToNew() {
    this[NavigationMixin.Navigate]({
        type: 'standard__objectPage',
        attributes: {
           objectApiName: this.objectName,
           actionName: 'new'
        }        
    });
}

Once the user saves the new child-detail record, however, they are directed to the new child-detail record page, and I would like them to remain on the original parent-master record page on which they started.

Basically, the idea is to create detail records from a master record without leaving the master record detail page. I don't see anything like this in the documentation – https://developer.salesforce.com/docs/component-library/bundle/lightning-navigation/documentation – is it just not possible using the 'standard__objectPage' type?

Many thanks

Best Answer

You can achieve by using pagereference as Web Page Type in lightning navigation.

       this[NavigationMixin.Navigate]({
            type: 'standard__webPage',
            attributes: {
                url: '/lightning/o/Contact/new?count=2&nooverride=1&useRecordTypeCheck=1&navigationLocation=RELATED_LIST'
            }
        });

When you use navigationLocation=RELATED_LIST , it will not navigate to child record upon save. It will remain on parent.

Related Topic