I would like to open a tab of a Contact in a Service Console:

sforce.console.openPrimaryTab(null, CONTACT_ID, true);

I can't make it though when it's already opened. I receive an error in browser's console:

openPrimaryTab: Opening a duplicate tab is not allowed.

I know I can focus the tab having its Id but I don't always have it - sometimes there are some tabs opened from previous sessions or I opened one manually.

I thought that I maybe could somehow distinguish already opened tabs but I looked through a Salesforce Console Developer Guide and I didn't find anything useful.

2 Answers 2


This small piece of code perfectly works for me.

Rather than first argument as null, I have used undefined. secondly, use tabName parameter and make this tabName as unique. And then based on tabname it will focus on Primary tab.

call this callOpenPrimaryTab function either from button click or URL.

function callOpenPrimaryTab(contactId,contactName) 
        sforce.console.openPrimaryTab(undefined,"/"+contactId, true, contactName, openSuccess,contactId+contactName);
        sforce.console.focusPrimaryTabByName(contactId+contactName, focusSuccess);

var openSuccess = function openSuccess(result) {
    //Report whether opening the new tab was successful
    if (result.success == true) {
        //alert('Primary tab successfully opened');
    } else {
        //alert('Primary tab cannot be opened');
  • What in a situation when I've already opened tab manually? In a console I receive focusPrimaryTabByName: Invalid Name: 0030E00000HQvF1QALCONTACT NAME openPrimaryTab: Opening a duplicate tab is not allowed. Feb 20, 2018 at 10:31

So there's a way to do that. I used getPrimaryTabIds() to get an array of tabs' ids and then getPageInfo() to extract an information from the tab. If it's a tab of an object, a pageInfo field contains an objectId field with an Id of the viewed object. Then I simply compare every tab object's Id with an Id of the one I want to be opened:

var sid = MY_OBJECT_ID;
sforce.console.openPrimaryTab(null, "/" + sid, true, undefined, function(response) {
    if (!response.success) {
        sforce.console.getPrimaryTabIds(function(response) {
            var primaryTabIds = response.ids;
            for (let id of primaryTabIds) {
                sforce.console.getPageInfo(id, function(response) {
                    var myVar = JSON.parse(response.pageInfo);
                    var objectId = myVar.objectId;
                    if (objectId === sid) {

But I still hope there's a better answer.

  • check my answer it will help you Feb 19, 2018 at 18:16

You must log in to answer this question.

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