4

Background & The Problem

We have a custom grid lwc which i am using to display data from two different objects (EmailMessage & CustomObject). Now, I want to navigate the user to a new tab with Contact as Primary tab and Case as Sub-tab when they click on CaseNumber. I am able them to navigate to a new tab (Case) by using NavigationMixin.Navigate (code shown below) but not sure how to open it as a sub-tab without using workspaceapi since LWC doesn't support it yet.

handleGenericClick(){
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: this.caseId,
                actionName: 'view'
            }
        });
    }
3

I can suggest one of the approaches that we adopted on our projects.

Wrapping into Aura might be tedious, so I suggest creating an Aura Utility bar component (you can also use hidden Utility Component) and communicate with it through Messaging Channel.

This way you can re-use the same logic anywhere in your Application or potentially in other projects.

SAMPLE CODE:

//LWC
import globalApiChannel from "@salesforce/messageChannel/globalApiChannel__c";

action() {
    publish(this.msgContext, globalApiChannel, {
      action: 'open-subtab',
      params: {
        recordId: caseId,
        actionName: 'view'
      }
    });

}

<!--aura.cmp-->
    <lightning:messageChannel type="globalApiChannel__c"
                              onMessage="{!c.handleUtilityMessage}"
                              scope="APPLICATION"
    />
// auraController.js
    var action = event.getParam('action');
    var params = event.getParam('params');
    if (action === 'open-subtab') {
         // do your thing
    }
5
  • FYI cannot include an Aura Component inside a Lightning Web Component (reference), so the hidden Aura Component inside a Lightning Web Component won't work. This solution I believe will require using an Aura Utility Bar component. – Benjamin Luehrs Feb 22 at 7:19
  • 1
  • It's interesting how generally bad the "new" Salesforce tech is. The most basic actions are not implemented – Andy Ray Apr 8 at 20:38
  • LWC is much comfortable to build with, while Aura has some additional API due to Locker Service limitation for example – ytiq Apr 9 at 9:14
  • LWCs are one step forward and five steps back. They're built on web components which all other web ecosystems have abandoned as bad practice. They force a poor development experience with limited functionality and a half baked module system. The template system and error handling is sub par. It's still about 15 years behind modern development practices. – Andy Ray Apr 16 at 23:44
2

I think the only way to achieve this behaviour would be to wrap your component in an Aura wrapper and handle interaction with the workspace API there. The LWC component should bubble up an event to its Aura wrapper when the workspace API needs to be used.

1

This is possible via this https://mtr-design.com/news/salesforce-mini-how-to-open-a-subtab-in-console-from-lightning-web-component (Solution #2)

I just tried it and using internalapievent as custom event the workspace api events works.

Example is only given for openSubtab but you can try and edit for other events too.

0

Try this solution: enter link description here

In The section Solution #2, you can see how to invoke workSpaceApi in LWC (you may need to modify some parameters, for example in my case i needed to close the current tab, so instead of using the parameter parentTabId, i changed it to tabId

1
  • That actually worked!! Do you know how the workspace invoking happening with custom event? – SunnyG Apr 30 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.