1

I've been trying to refresh a primary tab from a subtab with no luck, and would like a working example. According to their doc, they do not give an example of how to retrieve your primary tab's id from a subtab. How do you retrieve this information without knowing the Id from using something like openPrimaryTab?

Doc: https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_refreshprimarytabbyid.htm?language=en

 <A HREF="#" onClick="testRefreshPrimaryTabById();return false">
     Click here to refresh a primary tab by id</A> 

<apex:includeScript value="/support/console/22.0/integration.js"/>
<script type="text/javascript">
    function testRefreshPrimaryTabById() {
        //Get the value for 'scc-pt-0' from the openPrimaryTab method
        //This value is for example purposes only
        var primaryTabId = 'scc-pt-0';
        sforce.console.refreshPrimaryTabById(primaryTabId, true, refreshSuccess);
    }

    var refreshSuccess = function refreshSuccess(result) {
        //Report whether refreshing the primary tab was successful
        if (result.success == true) {
            alert('Primary tab refreshed successfully');
        } else {
            alert('Primary did not refresh');
        }
    };

Example code I've tried out:

    var closeSubtab = function closeSubtab(result) {
        var tabId = result.id;
        sforce.console.closeTab(tabId);
    };

    var primaryTabId = function showTabId(result) {
        //Display the tab ID
        //alert('Tab ID: ' + result.id);
    };

    var refreshSuccess = function refreshSuccess(result) {
        //Report whether refreshing the primary tab was successful
        if (result.success == true) {
            alert('Primary tab refreshed successfully');
        } else {
            alert('Primary did not refresh');
        }
    };

    function closeTab() {
        sforce.console.refreshPrimaryTabById(primaryTabId, true, refreshSuccess);
        sforce.console.getEnclosingTabId(closeSubtab);
    }

    function exitWizard(){            
            if(sforce.console.isInConsole()){                                  
                closeTab();
            }else{
                window.location.href = '/' + recordId;   
            }
        }
    }

    exitWizard();
2

I finally was able to get this code working...

The documentation does not explain this well in my opinion. Basically, you create a variable, in this case called refreshPrimaryTab which is assigned to a function which will retrieve your primaryTabId and assign it to your request for a refresh. This though will not execute yet. In order to execute, you need to call a salesforce function. This is done by calling sforce.console.getEnclosingPrimaryTabId() with your variable inside. As the example shows it will look like: sforce.console.getEnclosingPrimaryTabId(refreshPrimaryTab);

Below is a simple example of how from a sub tab you can get your primary tab to refresh.

    var refreshPrimaryTab = function showTabId(result) {
        var tabId = result.id;
        sforce.console.refreshPrimaryTabById(tabId, true);
    };

    function doPrimaryTabRefresh() {
        sforce.console.getEnclosingPrimaryTabId(refreshPrimaryTab);            
    }

    doPrimaryTabRefresh();
| improve this answer | |
  • 1
    Glad you found it! Thumbs up – Willem Mulder Jun 26 '14 at 15:32
  • I keep reading people get this to work, but the result of my refreshes always show success=false. I get the Id without a problem, and apparently call the refresh without a problem, but the callback always returns success=false and the primary isn't refreshing. And nowhere can I find explanations for why a refresh would be unsuccessful, and the console log doesn't snow anything particularly interesting. – tggagne Mar 16 '16 at 1:49
1

Use

sforce.console.getPrimaryTabIds();

or

sforce.console.getFocusedPrimaryTabId();

See https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_getprimarytabids.htm?language=en and https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_getfocusedprimarytabid.htm?language=en

Alternatively, you could refresh the tabs by name:

sforce.console.refreshPrimaryTabByName(someName);

See https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_refreshprimarytabbyname.htm?language=en

| improve this answer | |
  • Yeah, I've tried these with no luck... please provide a working example... I'll some sample code I've tried with no luck. Also if you are working on Leads / Accounts / Contacts for example name will not work as you can have multiple John Smiths opened. – Double A Jun 26 '14 at 14:19

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.