I am trying to open a primary tab and subtab in the console app after user clicks button on visualforce page in custom console component. The subtab would be the opportunity entered in the input field on the vfpage and the primary tab would be the parent of th opportunity. I have been able to get it to open the primary tab, but I can't seem to get the subtab to open. Any idea what I'm doing wrong? Is this possible? Thanks in advance!

 <apex:includeScript value="/support/console/45.0/integration.js"/>
 <script type="text/javascript">   
     function openAccountTab() {
         if (sforce.console.isInConsole()) {
             sforce.console.openPrimaryTab(null, document.getElementById("{!$Component.mainForm.AcctId}").value, 
                                           false, document.getElementById("{!$Component.mainForm.AcctName}").value,
                                           openSubtab, 'AccountTab');
     var openSubtab = function openSubtab(result) {
         var primaryTabId = result.id;
         source.console.openSubtabById(primaryTabId, document.getElementById("{!$Component.mainForm.OppId}").value,
                                   true, 'OppName', null, openSuccess, 'OppTab');
     var openSuccess = function openSuccess(result) {
         if(result.success == true) {
             alert('subtab successfully opened');
         }else {
             alert('subtab cannot be opened');

<apex:pageBlock id="pbMain" title="Search Opportunity">

            <apex:inputText value="{!OpportunityName}" id="searchInput"/>

            <apex:actionStatus id="counterStatus" > 
                <apex:facet name="start" >
                    <span style="color:red;">Processing, Please Wait...</span>
                <apex:facet name="stop"> 
                    <apex:commandButton value="Search" action="{!ValidateOppName}" id="searchButton" 
                                        rerender="mainForm" oncomplete="openAccountTab();" />


1 Answer 1


It appears to me that you're looking for the focusSubtabByNameAndPrimaryTabName() method in the Salesforce Console Developer Guide. Below is example code from the documentation.

In your case, the primarytabName is Account and the subtabName is Opportunity. Adjust your code accordingly and be sure to start taking advantage of the Console Integration Toolkit which will save you a lot of development time!

<apex:page standardController="Case">

     <A HREF="#" onClick="testFocusSubtabByNameAndPrimaryTabName();return false">
         Click here to go to a subtab by name and primary tab name</A> 

    <apex:includeScript value="/support/console/45.0/integration.js"/>
    <script type="text/javascript">
        function testFocusSubtabByNameAndPrimaryTabName() {
            //Get the value for 'mySubtab' and 'myPrimaryTab' from the openSubtab method
            //These values are for example purposes only
            var subtabName = 'mySubtab';
            var primaryTabName = 'myPrimaryTab';
            sforce.console.focusSubtabByNameAndPrimaryTabName(subtabName, primaryTabName, focusSuccess);

        var focusSuccess = function focusSuccess(result) {
            //Report whether going to the subtab was successful
            if (result.success == true) {
                alert('Going to the subtab was successful');
            } else {
                alert('Going to the subtab was not successful');



You must log in to answer this question.

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