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
Shravan Kumar 71Shravan Kumar 71 

Open link in subtab in Lightning Console

Hello Trailblazers, 

When a user clicks on the link, it should open in a subtab in lightning console. Below is the VF page that I have come up with, however it's not working as expected. Any inputs will be highly appreciated. 
 
<apex:page standardController="LiveChatTranscript" extensions="PastChatSearchController">
    <apex:includeScript value="/support/console/45.0/integration.js"/>
    
    <script>
    var preRecordId;    
    function openSubtab(id, name) 
    {
        preRecordId= id;    
        alert('URL----->'+'{!$CurrentPage.URL}');        
        if (sforce.console.isInConsole())
            sforce.console.getEnclosingPrimaryTabId(openSubtab);
        else
            window.top.location.href = '/' + id;
    }
    
    var openSubtab = function openSubtab(result) 
    {
        var primaryTabId = result.id;        
        sforce.console.openSubtab(primaryTabId, '/'+preRecordId, true, preRecordId , null , openSuccess, 'salesforceSubtab');
    };
    </script>
        
    <apex:form >
        <apex:pageBlock id="pb">
            <apex:pageMessages ></apex:pageMessages>
            <apex:pageBlockTable value="{!LiveChatTranscript}" var="d">
                <apex:column headerValue="Live Chat Transcript Name">
             <!--       <apex:outputLink target="_blank" style="color:blue" value="{!URLFOR($Action.LiveChatTranscript.View, d.ID)}"> {!d.Name} 
                    </apex:outputLink> -->
                    
                    <a href="#" onclick="openSubtab('{!d.id}', '{!d.id}');return false">{!d.Name}</a>
                </apex:column>
                
                <apex:column headerValue="CreatedDate">                  
                    <apex:outputField value="{!d.CreatedDate}">                               
                    </apex:outputField>                   
                </apex:column>
                
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>    
</apex:page>

Thank you
Shravan
Khan AnasKhan Anas (Salesforce Developers) 
Hi Shravan,

Greetings to you!

Please refer to the below links which might help you further with the above requirement.

https://salesforce.stackexchange.com/questions/195801/open-link-as-subtab-in-console-view-and-a-new-browser-tab-otherwise

https://developer.salesforce.com/forums#!/feedtype=SINGLE_QUESTION_SEARCH_RESULT&id=906F0000000BTpTIAW

https://developer.salesforce.com/forums/?id=9060G000000XfF8QAK

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Raj VakatiRaj Vakati
I can suggest to use the lightning console  workspace API .. 

Please refer this code

https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_lightning_openSubtab.htm

​​​​​​​
<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
    <lightning:workspaceAPI aura:id="workspace" />
    <lightning:button label="Open Tab with Subtab" onclick="{! c.openTabWithSubtab }" />
 </aura:component>
 
({
    openTabWithSubtab : function(component, event, helper) {
        var workspaceAPI = component.find("workspace");
        workspaceAPI.openTab({
            url: '/lightning/r/Account/001xx000003DI05AAG/view',
            focus: true
        }).then(function(response) {
            workspaceAPI.openSubtab({
                parentTabId: response,
                url: '/lightning/r/Contact/003xx000004Ts30AAC/view',
                focus: true
            });
        })
        .catch(function(error) {
            console.log(error);
        });
    }
})