9

I'm using lightning navigation to redirect to a standard record page. However, the redirection takes place in the same tab. Is there a way to open a new tab?

navigateToRecord(event){
        var sRecordId = event.target.dataset.id;
        if(sRecordId!=='' && sRecordId!==undefined ){
            this[NavigationMixin.Navigate]({
                type: 'standard__recordPage',
                attributes: {
                    recordId: sRecordId,
                    objectApiName: 'My_Object__c',
                    actionName: 'view'
                },
            });
        }
        
    }
1
  • do you mean new tab on browser or new tab on console app?
    – User6670
    Jul 22, 2020 at 11:15

1 Answer 1

16

Use NavigationMixin.GenerateUrl. Then use window.open to open in a new window.

this[NavigationMixin.GenerateUrl]({
    type: "standard__recordPage",
    attributes: {
        recordId: sRecordId,
        objectApiName: 'My_Object__c',
        actionName: 'view'
    }
}).then(url => {
    window.open(url, "_blank");
});
5
  • I actually tried this already. Seems, the redirection takes places before .then() gets called. So it doesn't even enter the .then() context.
    – sfdcnoob
    Jul 22, 2020 at 11:55
  • Did you try this code? @sfdcnoob Jul 22, 2020 at 12:00
  • 3
    @sfdcnoob its this[NavigationMixin.GenerateUrl] not this[NavigationMixin.Navigate]
    – User6670
    Jul 22, 2020 at 12:00
  • @RahulGawale I am using the above to show standard new creation page however it open a Modal. I want to show it on new salesforce tab in same window tab instead of new window tab and Modal. How can I achieve this? Feb 28, 2023 at 9:06
  • @sfdcLearner new form will always open in modal instead of new page. This is standard behaviour Mar 1, 2023 at 5:41

You must log in to answer this question.

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