function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kelly KKelly K 

sforce.console.getEnclosingPrimaryTabId() returning undefined

I'm having trouble figuring out why the following code is not returning an Id so I can get to the point of refreshing my tab. I'm in debug mode and basically what I'm finding is that sforce.console.getEnclosingPrimaryTabId() is returning null. The event listener is firing correctly, so I know it's not an issue with that.

Does anyone see an obvious error that I don't or know of a bug that could be affecting this? Even if I rip the code straight out of Salesforce's documentation, I found that no results are returned.
<apex:page standardController="Account" extensions="FC_AccountExtension" title="{!account.Name}">
    <apex:detail relatedList="true"/>

    <apex:includeScript value="/support/console/31.0/integration.js"/>
    <script type='text/javascript'>
        //Set the title of the tab of the VF page to match the account
        sforce.console.setTabTitle('{!account.Name}');
        
        var listener = function (result) {
            alert('Message received from event: ' + result.message);
        };

        function refreshDetailListener() {
            console.log('refreshDetailListener fired!');

            var enclosingPrimaryTabId = sforce.console.getEnclosingPrimaryTabId();                
            console.log('enclosingPrimaryTabId: ' + enclosingPrimaryTabId );
            
            var enclosingTabId = sforce.console.getEnclosingTabId();    
            console.log('enclosingTabId: ' + enclosingTabId);
        }       
        
        //Add listeners
        sforce.console.addEventListener('SampleEvent', listener);
        sforce.console.addEventListener('refreshDetail', refreshDetailListener);
    </script>
</apex:page>


Gaurav NirwalGaurav Nirwal
VF Page
<A HREF="#" onClick="openReportedContact();return false">{!caserec.contact.name}</A>

function openReportedContact() {
     if(!sforce.console.isInConsole())
         window.parent.location.replace('/{!case.ContactId}');
     else sforce.console.getEnclosingPrimaryTabId(callBackopenReportedContact);
}

function callBackopenReportedContact(result) {
 sforce.console.openSubtab(result.id, '/{!case.ContactId}',true,'{!case.contact.name}', null);
};

Kelly KKelly K
Not quite what I'm after... 

This is what I'm trying to do - refresh the detail page when a console component calls it. However, the sforce.console.getEnclsoingPrimaryTabId() function (even when using a callback) is not returning an Id.

Am I using it wrong?
<apex:page standardController="Account" extensions="FC_AccountExtension" title="{!account.Name}">
    <apex:detail relatedList="true"/>

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

    <script type='text/javascript'>
        //Set the title of the tab of the VF page to match the account
        sforce.console.setTabTitle('{!account.Name}');
        
        var listener = function (result) {
            alert('Message received from event: ' + result.message);
        };

        var refreshDetailListener = function() {
            console.log('refreshDetailListener fired!');

            sforce.console.getEnclosingPrimaryTabId(function() {
                console.log('getEnclosingPrimaryTab subfunction opened');
                sforce.console.refreshPrimaryTabById(result.Id, true);
            });
        }       
        
        //Add a listeners
        sforce.console.addEventListener('SampleEvent', listener);
        sforce.console.addEventListener('refreshDetail', refreshDetailListener);
    </script>
</apex:page>
Chris VogeChris Voge
Change to:

sforce.console.getEnclosingPrimaryTabId(function(result) {
         console.log('getEnclosingPrimaryTab subfunction opened');
         sforce.console.refreshPrimaryTabById(result.Id, true);
});
 
Kelly KKelly K

Hi Chris,

Thank you for your response. One of the devs I was working with ended up logging a case with Salesforce support on this. Essentially, they told him that while this functionality can only be replicated through Javascript and not through apex & visualforce - it is an issue specifically with javascript and not a bug in apex:detail element. They told him not to use javascript to invoke a refresh, though they did say that there is no way to properly do the refresh in the console other than using javascript.

So unfortunately, it seems having an automated detail page refresh on update of a component is not possible at this time.