When Salesforce is life!

[Salesforce / CloudConsole] How to get if a tab is the primary tab

Spread the love

This is a quick post for the future me that will be struggling with Cloud Console and tab handling.

I wanted to get it a tab is a primary tab, in order to decide whether to open a new page in a new primary tab or in a subtab.

The problem is that if you try to get the primary tab id of a primary tab with the

sforce.console.getEnclosingPrimaryTabId()

function and get the value with the

sforce.console.getEnclosingTabId()

(expecting the same value for primary tabs), we instead get different values, as if the primary tab is enclosed in a super primary tab.

To solve this problem, just get the page info details and check if the enclosing primary tab has the same URL of the enclosing tab, and that’s it:

function isPrimaryTab(callback){
  sforce.console.getEnclosingPrimaryTabId(function (result){
    currentPrimaryTabId = result.id;
    sforce.console.getEnclosingTabId(function (subtabResult){
        thisTabId = subtabResult.id;
        sforce.console.getPageInfo(currentPrimaryTabId, function(pageinfo1){
            sforce.console.getPageInfo(thisTabId, function(pageinfo2){
                return callback && callback(JSON.parse(pageinfo2.pageInfo).url === JSON.parse(pageinfo1.pageInfo).url);
            });
        });
    }); 
  });
});

isPrimaryTab(function(result){
   alert(((result)?'IT IS':'IT IS NOT') + ' A PRIMARY TAB!');
});

Previous

[Salesforce / Lightning] Simple Custom Modal Alert

Next

[Salesforce] Summer17 Awesome Features Selection

1 Comment

  1. Rohan Kumbhar

    Thanks alot…It helped

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Powered by WordPress & Theme by Anders Norén