0

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()) { 
        sforce.console.getEnclosingPrimaryTabId(openSubtabs);
    }else{
        window.parent.location.href="/00T/e?who_id={!userId}&what_id={!opp.Id}&retURL=%2F{!opp.Id}";
    }
}

var openSubtabs = function openSubtabs(result) {
    sforce.console.openSubtab(result.id,'/00T/e?who_id={!userId}&what_id={!opp.Id}&retURL=%2F{!opp.Id}',true,'',null);
    sforce.console.refreshPrimaryTabById(result.id , true);
};  

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

}
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.

https://developer.salesforce.com/docs/atlas.en-us.api_cti.meta/api_cti/sforce_api_cti_runapex.htm

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.

https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/intro_stream.htm

|improve this answer|||||

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.