0

We have a visualforce page that acts as a list view in the console. When the user clicks a link on this page to open a case, the case is opened as a subTab of the contact (per settings in the app).

We have another link that opens a custom visualforce page. We want this page to be opened as a subtab of contact as well. I have the following code:

function openStudentProfile(contactId, contactName) {
        if (sforce.console.isInConsole()) {
            sforce.console.openPrimaryTab(null, './' + contactId, true, contactName, function(result) {
                if (result.success) {
                    sforce.console.openSubtab(result.id, '/apex/studentProfile?id=' + contactId, true, contactName + ' Student Profile', null);

                    if (primaryTabIds.indexOf(result.id) < 0) {
                        primaryTabIds.push(result.id);
                    }
                } else {
                    sforce.console.getPrimaryTabIds(function (primaryTabResult) {
                        for (x = 0; x < primaryTabResult.ids.length; x++) {
                            sforce.console.getPageInfo(primaryTabResult.ids[x], function(pageInfoResult) {
                                if (pageInfoResult.success) {
                                    var info = JSON.parse(pageInfoResult.pageInfo);

                                    if (info.objectId == contactId.substring(0, 15)) { // contactId is 18 digit, ObjectId is 15
                                        //Variable 'a' needs to have ID of the tab that this page is in
                                        sforce.console.openSubtab(a, '/apex/studentProfile?id=' + contactId, true, contactName + ' Student Profile', null);
                                    }
                                }
                            });
                        }
                    });
                }
            });
        }
    }

If the contact tab is not open, everything works. The issue happens when the contact tab is already open. We receive an error saying duplicate tabs are not allowed. To handle this, we get a list of all primary tabs, get the tab's page's information and compare it to the contact Id.

When the correct Tab is found, we need it to open a subtab with the custom vf page. The problem is that there seems to be no way to get the parent Tabs Id within the getPageInfo callback.

I have tried to return a boolean from the callback through various means so that I can open the tab from within the primaryTabIds callback (similar question) to no avail (the method in the previous question did not work).

I need help opening this custom vf page as a subtab of a contact tab that is already open.

0

Below is what I ended up doing:

function openStudentProfile(contactId, contactName) {
        var isFound = false;

        if (sforce.console.isInConsole()) {
            sforce.console.openPrimaryTab(null, './' + contactId, true, contactName, function(result) {
                if (result.success) {
                    sforce.console.openSubtab(result.id, '/apex/studentProfile?id=' + contactId, true, contactName + ' Student Profile', null);

                    if (primaryTabIds.indexOf(result.id) < 0) {
                        primaryTabIds.push(result.id);
                    }
                } else {
                    sforce.console.getPrimaryTabIds(function (primaryTabResult) {
                        for (x = 0; x < primaryTabResult.ids.length; x++) {
                            console.log(primaryTabResult.ids[x]);
// note: you must assign this value to a variable. It doesn't seem to work when you try to pass primaryTabResult.ids[x] as a default value directly
                            var parentTabId = primaryTabResult.ids[x];

// Pass the parent Id as the default value to a second parameter. Since SF Only passes 1 parameter to the call back, this is never overridden                                
                            sforce.console.getPageInfo(primaryTabResult.ids[x], function(pageInfoResult, pId = parentTabId) {
                                if (pageInfoResult.success) {
                                    var info = JSON.parse(pageInfoResult.pageInfo);

                                    if (info.objectId == contactId.substring(0, 15)) { // contactId is 18 digit, ObjectId is 15
                                        sforce.console.openSubtab(pId, '/apex/studentProfile?id=' + contactId, true, contactName + ' Student Profile', null);
                                    }
                                }
                            });
                        }
                    });
                }
            });
        }
    }

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.