function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC Forum 9SFDC Forum 9 

OpenSubTab in lightning console

Hey folks, I have requirement pls help me.

I have menu bar with items in it in classic , all the items in it are basically other system tabs.When ii click on them, new sub tab will open and show the information of another system. It works fine in classic.
in VF, sfoce.console.getfocusedsubtabid  & sforce.console.openSubTab is used.

Now I will have to migrate this vf page.Could not do with existing vf code.

So i have started creating lightning component.On click , i have to write controller , referring this below code to do so.


({
02    openTabWithSubtab : function(component, event, helper) {
03        var workspaceAPI = component.find("workspace");
04        workspaceAPI.openTab({
05            url: '/lightning/r/Account/001xx000003DI05AAG/view',
06            focus: true
07        }).then(function(response) {
08            workspaceAPI.openSubtab({
09                parentTabId: response,
10                url: '/lightning/r/Contact/003xx000004Ts30AAC/view',
11                focus: true
12            });
13        })
14        .catch(function(error) {
15            console.log(error);
16        });
17    }
18})




But in my case I am confused what should I pass under workspace.openTab   &  workspaceAPI.openSubtab, bcz I dont have URL and things like that.
 can anyone of you suggest me.



OR can anyone suggest me how to use existing vf code and make it working in lightning, bcz this would be easy task
{tushar-sharma}{tushar-sharma}
You need to use Workspace API (https://developer.salesforce.com/docs/component-library/bundle/lightning:workspaceAPI/documentation) to make it work in lightning.
<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
    <lightning:workspaceAPI aura:id="workspace" />
    <lightning:button label="Open Tab" onclick="{! c.openTab }" />
</aura:component>


(
    openTab : function(component, event, helper) {
        var workspaceAPI = component.find("workspace");
        workspaceAPI.openTab({
            url: '#/sObject/001R0000003HgssIAC/view',
            focus: true
        });
    },
)}

It has many methods including openSubtab that will work for you.
If this answer helps you, please mark it as accepted.

Regards,
Tushar Sharma
https://newstechnologystuff.com/​​​​​​​ (https://newstechnologystuff.com/)
 
SFDC Forum 9SFDC Forum 9
Thank you for quick response as always Tushar :-)

I have used workspace API.I dont think i can use the above code alone.
bcz there are two points.

I will insert my component in below page.

1)  I need to open sub tab in the existing tab or sub tab beside 'Detail' as highlihted in screenshot.
So as per my understanding in classic vf code, it is capturing enclosedtab Id as soon as page loads.Then user click on any menu item, it takes that main tab Id and gets details through web service and displays.

so when  i use code given by you, there is no scope of mentoning sub tab details.
So I used this below code, it works exactly as per my requirement, but my problem is, since i am new to this, I am not  getting what to pass as URL under openTab and URL under openSubTab.please suggest.


({
02    openTabWithSubtab : function(component, event, helper) {
03        var workspaceAPI = component.find("workspace");
04        workspaceAPI.openTab({
05            url: '/lightning/r/Account/001xx000003DI05AAG/view',
06            focus: true
07        }).then(function(response) {
08            workspaceAPI.openSubtab({
09                parentTabId: response,
10                url: '/lightning/r/Contact/003xx000004Ts30AAC/view',
11                focus: true
12            });
13        })
14        .catch(function(error) {
15            console.log(error);
16        });
17    }
18})


User-added image


 
David Zhu 🔥David Zhu 🔥
1. First step is to define workspace attribute in html file. I believe you already have done.
<lightning:workspaceAPI aura:id="workspace" />

2. Use the following code snippet to open a subtab. This will open Account record on a Contact page.
var workspaceAPI = cmp.find("workspace");
		
workspaceAPI.getFocusedTabInfo().then(function(response) {
var resp1 = response.tabId;  //get "detail" tab Id

workspaceAPI.openSubtab({   //open new tab as a subtab
    parentTabId: response.parentTabId,   //get parettab id
    pageReference: {
        "type": "standard__recordPage",   //standard record type
        "attributes": {
            recordId: "001xx000003DI05AAG",    //assign record Id
            objectApiName: "Account",          //assign sojbect name
            actionName: "view"
        },
    },
    focus: true
    }).then(function(response){
    });
    $A.get('e.force:refreshView').fire();
});


 
SSP AdminSSP Admin
Hello SFDC Forum 9

It looks like our team of experts can help you resolve this ticket. We have Salesforce global help-desk support and you can log a case and our Customer Success Agents will help you solve this issue. You can also speak to them on live chat. Click on the below link to contact our help-desk. Trust me it is a support service that we are offering for free!

https://jbshelpdesk.secure.force.com/

Thanks,
Jarvis SFDC team
{tushar-sharma}{tushar-sharma}
ThHere are many methods which you can use eg: getAllTabInfo(), getEnclosingTabId() to get these details. In the end sample code was mentioned which you can refer.
SFDC Forum 9SFDC Forum 9
Hi, I have used like this for this as below.i got my requirement.Now My concern, this tab is not showing any details when I refresh page.Please suggest.
CMP:

<lightning:buttonMenu alternativeText="Toggle menu" label="Partcipant Info" onselect="{!c.doRedirect:doRedirect}" >
 
    <lightning:menuItem label="Home Page" value="menuitem1" iconName="utility:table"/>


JS:: doRedirect:   workspaceAPI.openTab({
              url:URL,
              focus: true
     
      }).catch(function(error) {
              console.log(error);
     });