0

I've been working on a custom console component that displays solutions, and opens them as a subtab if user is viewing a tab, and opens as primary tab otherwise.

Open as subtab works properly. I'm using the onFocusedPrimaryTab and getFocusedPrimaryTabId methods to keep a variable named parentTabIdrXt in sync.

The only thing that doesnt work is when a user closes the last tab, or when user switches to navigation tab.

When the last tab is closed, the getFocusedPrimaryTabId method appears to retain the value of the last-closed tab (or maybe i'm doing something wrong).

When user switches to navigation tab, the most recent tab Id is stored in the parentTabIdxRt variable.

So, my question - is there a method or a better approach that would allow me to open solution in a primary tab when user is on the navigation tab? Both of the scenarios above result in the user going to the navigation tab. I could not find a suitable method or example in the documentation.

Here is the code for the visualforce page:

<apex:page standardController="Solution" recordSetVar="sols">

<apex:variable value="{!LEFT($Api.Partner_Server_URL_260, FIND( '/services', $Api.Partner_Server_URL_260))}" var="instanceURL"/>

<apex:includeScript value="/support/console/38.0/integration.js"/>

<script type="text/javascript">
        var primaryTabIdxRt;
</script>

<script type="text/javascript">
        function refreshPrimaryTabId() {
            sforce.console.getFocusedPrimaryTabId(processTab);
            }
            var processTab = function processTab(result) {
                primaryTabIdxRt = result.id;
                console.log('primaryTabIdxRt RefreshTab  = '+ primaryTabIdxRt);
        }
        sforce.console.addEventListener(sforce.console.ConsoleEvent.CLOSE_TAB,
                                refreshPrimaryTabId);
</script> 

<script type="text/javascript">
        var eventHandler = function (result) {
            primaryTabIdxRt = result.id;
            console.log('primaryTabIdxRt onFocusedPT = ' + primaryTabIdxRt);
        }
        sforce.console.onFocusedPrimaryTab(eventHandler);
</script> 


<script type="text/javascript">
        function openSolution(recURL) {
            console.log('OpenSolutionInitial = ' + primaryTabIdxRt);
             if (primaryTabIdxRt === null || primaryTabIdxRt == 'null') {
                console.log('OpenInPrimaryTabNull = ' + primaryTabIdxRt);
                sforce.console.openPrimaryTab(null,recURL,true);
                }
            else if (primaryTabIdxRt === undefined) {
                console.log('OpenInPrimaryTabUnd = ' + primaryTabIdxRt);
                sforce.console.openPrimaryTab(null,recURL,true);
                }
            else {
                console.log('OpenInSubtab = ' + primaryTabIdxRt);
                sforce.console.openSubtab(primaryTabIdxRt,recURL,true); 
            }    
        }
</script>  

<apex:pageBlock >

        <apex:form >
            <apex:panelGrid >
                <apex:selectList value="{!filterId}" size="1" id="selList">
                <apex:actionSupport event="onchange" rerender="list"  />
                <apex:selectOptions value="{!listViewOptions}"></apex:selectOptions>
                </apex:selectList>
            </apex:panelGrid>
                </apex:form>
                <apex:outputPanel layout="block" style="overflow:auto; height:300px; padding-right:3px;">
                <apex:pageBlockTable var="s" value="{!sols}" id="list">
                    <apex:column ><a href="#" onclick="openSolution('{!instanceURL}/{!s.Id}');">{!s.SolutionName}</a></apex:column>
                </apex:pageBlockTable>                
                </apex:outputPanel>    
</apex:pageBlock>
</apex:page>
1

You have to call sforce.console.getFocusedPrimaryTabId() again in OpenSolution() method before if conditions, then it will take correct primaryTabIdxRt

function openSolution(recURL) {
    sforce.console.getFocusedPrimaryTabId(processTab, true);

    if (primaryTabIdxR.......){
    }
}

Please refer my answer in your last question Console component tries to open in subtab when primaryTabId is null

Update

Can you please take this code and let me know if that meets your ideal scenario (user is viewing nav tab, then the solution would open as a primary tab). For me this is working. Again I am opening dummy Lead record as opposed to Solutions.

<apex:page standardController="Case">

    <apex:includeScript value="/support/console/29.0/integration.js"/>
    <script type="text/javascript">
        var primaryTabIdxRt;

        function refreshPrimaryTabId() {
            alert('inside refreshPrimaryTabId');
            sforce.console.getFocusedPrimaryTabId(processTab, true);
            }

            var processTab = function processTab(result) {
                primaryTabIdxRt = result.id;
                alert('primaryTabIdxRt=' + primaryTabIdxRt);

            }

            function testOpenPrimaryTab() {
                recURL = 'https://cs21.salesforce.com/00Qq0000004iHC2';  //lead id
                sforce.console.getFocusedPrimaryTabId(processTab, true);

                alert('OpenSolutionInitial = ' + primaryTabIdxRt);

                 if (primaryTabIdxRt == null || primaryTabIdxRt == 'null') {
                    alert('OpenInPrimaryTabNull = ' + primaryTabIdxRt);
                    sforce.console.openPrimaryTab(null,recURL,true);
                    }
                else if (primaryTabIdxRt == undefined) {
                    alert('OpenInPrimaryTabUnd = ' + primaryTabIdxRt);
                    sforce.console.openPrimaryTab(null,recURL,true);
                    }
                else {
                    alert('OpenInSubtab = ' + primaryTabIdxRt);
                    sforce.console.openSubtab(primaryTabIdxRt,recURL,true); 
                } 
                window.location.reload();
            }

    </script>
    <apex:form >
         <a href="#" onclick="testOpenPrimaryTab(); return false;">Click here</a>

      <apex:commandButton onclick="refreshPrimaryTabId(); return false;" title="ClickMe" value="Refresh Primary Tab ID" rerender="selList" />
    </apex:form>
</apex:page>
  • I missed that in your previous answer - that works quite well! The only scenario it doesnt cover is when user goes to navigation tab, but still has a primary tab open. My ideal scenario is that if user is viewing nav tab, then the solution would open as a primary tab, but doesnt seem to be any method that will tell when user is on navigation tab? – gorav Feb 6 '17 at 21:03
  • Can you please take this code, create a separate page and try to run this code, It seems to me working at my DE – Santanu Boral Feb 6 '17 at 21:34
  • thanks @santanu - i copied your example verbatim and only changed the recURL to a valid lead ID in my instance. I'm finding that it will open in a new tab every time - it will never open in a subtab. That is why it appears to work on the nav tab. Try opening a case and clicking the link - does it open in a subtab for you? – gorav Feb 8 '17 at 2:48
  • it is working fine – Santanu Boral Feb 8 '17 at 3:48

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.