2

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

2 Answers 2

1

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.

1
  • Thanks, I realized you can do what you were describing by using the state object as well. But when you do this, the parent record page does not refresh to show the newly created child record. Is there a way to force this refresh so that the newly created record is shown? I tried putting "refreshApex(this.records);" inside the "NavigationMixin.Navigate" function but it did not work.
    – number41
    Commented Sep 13, 2020 at 15:12
4

Another way I found of doing what Sanket was referring to above:

    navigateToNew() {
        this[NavigationMixin.Navigate]({
            type: 'standard__objectPage',
            attributes: {
                objectApiName: this.objectName,
                actionName: 'new'
            },
            state: {
                nooverride: 1,
                useRecordTypeCheck: 1,
                navigationLocation: 'RELATED_LIST',
                backgroundContext: '/lightning/r/Opportunity/'+this.recordId+'/view'
            }        
        }); 

You must log in to answer this question.

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