openSubtabByPrimaryTabName()

Opens a new subtab (within a primary tab) that displays the content of a specified URL, which can be relative or absolute. You can also override an existing subtab. Use to open a new subtab on a primary tab via the primary tab’s name. This method is only available in API version 22.0 or later.

If there’s an error opening the tab, the error code is reported in the JavaScript console.

Syntax 

1sforce.console.openSubtabByPrimaryTabName(primaryTabName:String, url:URL, active:Boolean, tabLabel:String, id:String, (optional)callback:Function, (optional)name:String)

Arguments 

NameTypeDescription
primaryTabNamestringName of the primary tab in which the subtab opened.
urlURLURL of the opened subtab. If the URL is to a Salesforce object, that object displays as specified in the Salesforce console app settings. For example, if cases are set to open as a primary tab, and openSubtab() is called on a case, the case opens as a primary tab. Users can open an external URL if it’s been added to the console’s allowlist.
activebooleanIf true, the opened subtab displays immediately. If false, the opened subtab displays in the background and the current tab maintains focus.
tabLabelstringOptional label of the opened subtab. If a label isn’t specified, External Page displays. Add labels as text; HTML isn’t supported.
idstringID of the subtab to override. Use null to create a new subtab.
callbackfunctionJavaScript method called upon completion of the method.
namestringOptional name of the opened subtab. This argument is only available in API version 22.0 and later.

Sample Code–Visualforce 

1<apex:page standardController="Case">
2
3    <A HREF="#" onClick="testOpenSubtab();return false">
4        Click here to open a new subtab by primary tab name</A> 
5
6    <apex:includeScript value="/support/console/68.0/integration.js"/>
7    <script type="text/javascript">
8        function testOpenSubtabByPrimaryTabName() {
9            //First open a primary tab by name
10            sforce.console.openPrimaryTab(null, 'http://www.yahoo.com', true, 'Yahoo', openSubtab, 'yahoo');
11        }
12        
13        var openSubtab = function openSubtab(result) {
14            //Open the subtab by the name specified in function testOpenSubtabByPrimaryTabName()
15            sforce.console.openSubtabByPrimaryTabName('yahoo', 'https://salesforce.com', true, 
16                'salesforce', null, openSuccess);
17        };
18        
19        var openSuccess = function openSuccess(result) {
20            //Report whether we succeeded in opening the subtab
21            if (result.success == true) {
22                alert('subtab successfully opened');
23            } else {
24                alert('subtab cannot be opened');
25            }
26        };
27    </script>
28</apex:page>

To see this example in action, click the custom link on a case. For more information, see Define Custom Buttons and Links in Salesforce Help.

Note

Response 

This method is asynchronous so it returns its response in an object in a callback method. The response object contains the following fields:

NameTypeDescription
successbooleantrue if the subtab successfully opened; false if the subtab didn’t open.
idstringID of the subtab. IDs are only valid during a user session; IDs become invalid when the user leaves the Salesforce console.