I am able to create a subtab from primary tab on the service console. How do I refresh the Primary Tab when subtab is deleted/closed/saved?

Below is the code to create a subtab from primary tab and primary tab is refreshed everytime a subtab is created.

function openNewSubtab() {
    sforce.connection.sessionId = '{!$Api.Session_ID}';
    if (sforce.console.isInConsole()) { 

var openSubtabs = function openSubtabs(result) {
    sforce.console.refreshPrimaryTabById(result.id , true);

var previousOnload = window.onload;
    window.onload = function() {
    if(previousOnload) {


1 Answer 1


You might be able to cobble together this kind of functionality out of the toolkits but mostly it's not native.

When subtab is closed

This one is easily supported with the console toolkit. You can add listeners on the CLOSE_TAB event and do your refresh when that event happens. https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_methods_events.htm

When subtab is deleted

I believe in theory you could do something here. When you delete a record its tab is closed. Using the above listener, you would check for result.objectId to get the ID of the record which is deleted.

In order to be sure the record was deleted and the tab wasn't just closed, you can use runApex method into a controller that tests if the record still exists. Pass in the objectId as a parameter, use apex to test for deletion and update a controller variable, and use a javascript callback to read that variable to verify its status. If it's deleted then you know the tab was closed due to deletion.


When subtab is saved

This is one I'm not entirely sure about how to do in a generic manner. You could try the onTabSave method but that only works when the dialog box pops up, not when a record is saved regularly. You could remove the Save button

Another option might be to use a custom button to override the Save method and using the SOAP API to call apex out of javascript and then do a reload as described here https://developer.salesforce.com/docs/atlas.en-us.workbook.meta/workbook/button_1.htm but this wouldn't be useful if a user did an inline save (unless you disable that ability). And you would probably need to create one such button for each object type this is needed for.

And for Cases specifically we have an event you can listen to https://developer.salesforce.com/docs/atlas.en-us.api_cti.meta/api_cti/sforce_api_cti_onobjectupdate.htm

Streaming API options

Another option for this would be to use the Streaming API to create a custom solution. Create topics on the objects you want, and write a VF component which will listen for the delete+save events and then refresh if the change matches one of your open tabs.


You must log in to answer this question.

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