Newer Version Available
openSubtabByPrimaryTabName()
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
| Name | Type | Description |
|---|---|---|
| primaryTabName | string | Name of the primary tab in which the subtab opened. |
| url | URL | URL 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. Note that users can open an external URL if it has been added to the console’s whitelist. For more information, see “Whitelist Domains for a Salesforce Console” in the online help. |
| active | boolean | If true, the opened subtab displays immediately. If false, the opened subtab displays in the background and the current tab maintains focus. |
| tabLabel | string | Optional label of the opened subtab. If a label isn't specified, External Page displays. Add labels as text; HTML isn't supported. |
| id | string | ID of the subtab to override. Use null to create a new subtab. |
| callback | function | JavaScript method called upon completion of the method. |
| name | string | Optional name of the opened subtab. This argument is only available in API version 22.0 and later. |
Sample Code–Visualforce
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<apex:page standardController="Case">
18
19 <A HREF="#" onClick="testOpenSubtab();return false">
20 Click here to open a new subtab by primary tab name</A>
21
22 <apex:includeScript value="/support/console/22.0/integration.js"/>
23 <script type="text/javascript">
24 function testOpenSubtabByPrimaryTabName() {
25 //First open a primary tab by name
26 sforce.console.openPrimaryTab(null, 'http://www.yahoo.com', true, 'Yahoo', openSubtab, 'yahoo');
27 }
28
29 var openSubtab = function openSubtab(result) {
30 //Open the subtab by the name specified in function testOpenSubtabByPrimaryTabName()
31 sforce.console.openSubtabByPrimaryTabName('yahoo', 'http://www.salesforce.com', true,
32 'salesforce', null, openSuccess);
33 };
34
35 var openSuccess = function openSuccess(result) {
36 //Report whether we succeeded in opening the subtab
37 if (result.success == true) {
38 alert('subtab successfully opened');
39 } else {
40 alert('subtab cannot be opened');
41 }
42 };
43 </script>
44</apex:page>Response
This method is asynchronous so it returns its response in an object in a callback method. The response object contains the following fields:
| Name | Type | Description |
|---|---|---|
| success | boolean | true if the subtab successfully opened; false if the subtab didn't open. |
| id | string | ID of the subtab. IDs are only valid during a user session; IDs become invalid when the user leaves the Salesforce console. |