Newer Version Available

This content describes an older version of this product. View Latest

openPrimaryTab()

Opens a new primary tab to display the content of the specified URL, which can be relative or absolute. You can also override an existing tab. This method is only available in API version 20.0 or later.
  • If the ID corresponds to an existing primary tab, the existing tab is redirected to the given URL because the Salesforce console prevents duplicate tabs.
  • 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 subtab of their parent accounts, and openPrimaryTab() is called on a case, the case opens as subtab on its parent account's primary tab.

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

Syntax

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

Arguments

Name Type Description
id string ID of the primary tab to override.

Use null to create a new primary tab.

If the ID corresponds to an existing primary tab, the existing tab is redirected to the given URL because the Salesforce console prevents duplicate tabs.

url URL URL of the opened primary tab.

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 subtab of their parent accounts, and openPrimaryTab() is called on a case, the case opens as subtab on its parent account's 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 primary tab displays immediately. If false, the opened primary tab displays in the background and the current tab maintains focus.
tabLabel string Optional label of the opened primary tab. If a label isn't specified, External Page displays.

Add labels as text; HTML isn't supported.

callback function JavaScript method called upon completion of the method.
name string Optional name of the opened primary tab.

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="testOpenPrimaryTab();return false">
20         Click here to open a new primary tab</A> 
21
22    <apex:includeScript value="/support/console/22.0/integration.js"/>
23    <script type="text/javascript">
24        function testOpenPrimaryTab() {
25            //Open a new primary tab with the salesforce.com home page in it
26            sforce.console.openPrimaryTab(null, 'http://www.salesforce.com', false, 
27                'salesforce', openSuccess, 'salesforceTab');
28        }
29        
30        var openSuccess = function openSuccess(result) {
31            //Report whether opening the new tab was successful
32            if (result.success == true) {
33                alert('Primary tab successfully opened');
34            } else {
35                alert('Primary tab cannot be opened');
36            }
37        };
38        
39  </script>
40
41</apex:page>

This example is set to run by clicking a custom link on a case. For more information, see “Defining Custom Buttons and Links” in the Salesforce online 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:

Name Type Description
success boolean true if the tab successfully opened; false if the tab didn't open.
id string ID of the primary tab. IDs are only valid during a user session; IDs become invalid when a user leaves the Salesforce console.