Sign up ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

In the service console toolkit its not possible to open same record in two tabs since the tabs needs to be unique, reasons for which i understand. But i am in a scenario where in, on clicking a link in the VF page i am trying to directly open a new primary tab and getting an error as "Cannot open primary tab :Duplicate tab exists". So basically i need to check if that record is already part of any of the primary or secondary tabs and if so i need to focus on that tab instead of opening a new tab.

But in the toolkit developer guide i dont see any methods available to check if the tab is part of the console. How to i implement the logic of checking if the record is already opened and only if not open a new tab, is there a better way than this logic?

share|improve this question
I reckon you will have handle the exception in a JavaScript try catch block and ignore it if the text matches. – techtrekker Dec 4 '12 at 13:09
but if u see the methods of the toolkit like getEnclosingPrimaryTabId(),getEnclosingPrimaryTabObjectId,getEnclosingTabId(),ge‌​tFocusedPrimaryTabId(),getFocusedPrimaryTabObjectId(),onFocusedPrimaryTab(),getFo‌​cusedSubtabId(), getFocusedSubtabObjectId() everything only tells me whats the primary or secondary tab in the context but i dont see any method which has visibility over the entire console tabs. – Anil Dec 4 '12 at 13:24
Hence why, handling the exception in javascript should work, so you don't proactively check if the tab is already open, but swallow the exception, if one occurs, where an attempt is being made to open an already open subtab. – techtrekker Dec 4 '12 at 13:38

1 Answer 1

We have couple of built in method to get the already opened primary/sub tab ids. I have achieved this as mentioned below:

Let say we have an Account as primary tab and Contact as sub tab. First of all on click of each contact record will open the tab using openPrimaryTab() and collect object id and primaryTabId in an object.

And when user tries to open a already opened tab, will iterate over already opened sub tabs until we find it, once we get the selected subTab then will focus on it.


sforce.console.openPrimaryTab(null, '/'+contactId, true, '', function callBack(result){

    // On each success collect parent ObjectId and parentTabId in an Object
        map[accountId] = result.Id;

    }else{ // Control will come here when record is already opened

        //Iterate over above parentId to get its subTabId to focus
        for(var key in map){

            // passing parent tab id to get its sub tab ids
            sforce.console.getSubtabIds(map[key] ,function callBack(result){

                var sTabIds = result.ids;

                var isSubTabFound = false;

                // Iterate over all sub tab id until we find the selected record
                for(var i=0; i<sTabIds.length; i++){


                        // passing sub tab id to get its object id to compare and focus
                        sforce.console.getPageInfo(sTabIds[i], function callBack(result) {


                                var sTabPageInfo = result.pageInfo;

                                if(sTabPageInfo.indexOf("/003") > -1){

                                    var getSubTabObjectId = sTabPageInfo.substr(sTabPageInfo.indexOf("/003")+1, 15);

                                    if(getSubTabObjectId == contactId){
                                        isSubTabFound = true;




                    if (isSubTabFound) break;


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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