1

I am trying to open a VF page as a subtab through a commandButton opensubtab in the VF page ParentVF. While the subtab opens for the first time, but if the opened subtab is cancelled/closed and the opensubtab button is clicked again the ParentVF itself loads again.

JS:

<apex:includeScript value="/support/console/34.0/integration.js"/>
    function openSTab(){
    var tid;
    var pg;
    var cid ='{!case.id}';
    if(sforce.console.isInConsole){
    sforce.console.getEnclosingPrimaryTabId(fetchTabId);
    }
    function fetchTabId(result){
    tid = result.id;
    pg = '/apex/ChildPage?id='+cid;
    sforce.console.getEnclosingTabId(openTab);
    }
    function openTab(result){
    sforce.console.openSubtab(tid,pg,true,'test',null,undefined,'test');
    }
    }

VF:

<apex:commandButton onclick="openSTab()"/>

At times the subtab is not opening at all.

2
  • Your command button is missing rerender along woth other required properties. Is it alowing to save you with just onclick?
    – Raul
    Commented Oct 21, 2017 at 14:00
  • hey Rahul. Could you please explain what are the required properties. As per the official documentation(example of opensubtab),I don't see rerender as required.
    – starhunter
    Commented Oct 21, 2017 at 14:18

1 Answer 1

0

You can take this approach to make your functionality workable

function openSTab() {   
    //First find the ID of the primary tab to put the new subtab in
    sforce.console.getEnclosingPrimaryTabId(openSubTabChildPage);
}

var openSubTabChildPage = function openSubTabChildPage(result) {
    //Now that we have the primary tab ID, we can open a new subtab in it
    var primaryTabId = result.id;

    sforce.console.refreshPrimaryTabById(primaryTabId, true, refreshSuccess);

    var pg = '/apex/ChildPage?id='+cid;

    sforce.console.openSubtab(primaryTabId , pg,true, 
        'Child Page', null, openSuccess, 'salesforceSubtab');
};

var refreshSuccess = function refreshSuccess(result) {
    //Report whether refreshing the primary tab was successful
    if (result.success == true) {

    } else {

    }
};

var openSuccess = function openSuccess(result) {
    //Report whether we succeeded in opening the subtab
    if (result.success == true) {

    } else {

    }
};

Visualforce

<apex:commandButton onclick="openSTab()" rerender="form1"/>
1
  • Thanks! But just to have a better understanding , could you also tell me why does this work. Rerender (from what I know) is to refresh a section of the vf page. However in my example the fetchTabId() method was not getting executed(found by putting logs). Would appreciate if you could explain this.
    – starhunter
    Commented Oct 21, 2017 at 17:17

You must log in to answer this question.

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