How do I know/find the Id or name of an already open primary tab in the console?

We are building a console app where accounts are opened as primary tabs. Some of these primary tabs will be opened from a visualforce page which has a short list of relevant/related accounts and basically calls sforce.console.openPrimaryTab(). In these calls we don't specify a tab Id but we can specify a tab name (eg. the accountId) meaning any subsequent clicks on entries in the relevant/related accounts list will send the user to the correct tab as expected.

However accounts can also be opened from a standard account list. So we have no control of the tab name. What we then see is

  • Account X has been opened from the standard list

  • The user is on the tab for another related/relevant account Y

  • In the list of related/relevant accounts the user now clicks account X The call to sforce.console.openPrimaryTab() will fail with "openPrimaryTab: Opening a duplicate tab is not allowed."

How do we find the Id or name of this tab so we can send the user there?

1 Answer 1


You need the getFocusedPrimaryTabId, or possibly getPrimaryTabIds:

(function (c) {
    "use strict";
    var focusedPrimaryTabId, allPrimaryTabIds;
    c.getFocusedPriaryTabId(function (result) {
        focusedPrimaryTabId = result.id;
    c.getPrimaryTabIds(function (result) {
        allPrimaryTabIds = result.ids;

Couple fun gotchas:

  • These methods do not return anything. You can only access their value from a callback.
  • Unlike Apex, Javascript properties are case sensitive, so result.Id won't work.
  • I actually have a working solution using both of the functions you mention. The code, however, is extremely complicated and one has to go to extreme lengths to make it work. The reason for my post is that I seek a more elegant solution to the problem. Perhaps if I rephrase the problem: From a standard list of accounts I click an account and a primary tab opens. Afterwards I click an account from a visual force page. How can I ensure that the already opened primary tab gets activated (the tab that opened when I clicked the account from a standard list)?
    – Andreas86
    Feb 29, 2016 at 13:24
  • Edit to above comment: "Afterwards I click THE SAME account..."
    – Andreas86
    Feb 29, 2016 at 13:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .