I know that there is workspaceAPI for aura development but I can't find anything in the web for lightning web component. Is there a way I can do this with LWC?
3 Answers
From the documentation lwc does not currently support the lightning console .
Workaround is to use aura components and if you have an lwc , wrap inside the aura components. This way you can bubble up an event and let the aura wrapper open the subtab.
-
2It's interesting how generally bad the "new" Salesforce tech is. The most basic actions are not implemented.– Andy RayCommented Apr 8, 2021 at 20:37
-
Less invasive refactor would be create "empty" (means not-displaying-anything) aura component, place it on page and set up communication with Lightning Message System to send info from LWC to open subtab. Commented Jun 9, 2022 at 10:21
Well my colleague managed to look for a solution for this using the import NavigationMixin:
HTML:
<a onclick={navigateToRecordViewPage} data-id={*lookup id*} target="_blank">{*lookup field*}</a>
JS:
import { NavigationMixin } from 'lightning/navigation';
add *** extends NavigationMixin(LightningElement)
method:
navigateToRecordViewPage(event) {
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: event.target.dataset.id,
actionName: 'view'
}
});
}
-
1I haven't tried this, but how does it know you want to open the page in a subtab, and assuming it knows that a subtab under what parent tab? Is it focused when opened? Commented Sep 17, 2020 at 15:58
try this one:
this[NavigationMixin.Navigate]({ type: 'standard__webPage', attributes: { url: '/lightning/r/Custom_Object__c/'+recordId +'/view?ws='+encodeURIComponent(window.location.pathname) }, });
Thanks