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.