1

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.

1

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) 
{ 
    if(sforce.console.isInConsole())
    {            
        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. – notmyf4ulty Feb 20 '18 at 10:31
0

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) {
                        sforce.console.focusPrimaryTabById(id);
                    }
                });
            }
        });
    }
});

But I still hope there's a better answer.

  • check my answer it will help you – Santanu Boral Feb 19 '18 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.