Newer Version Available

This content describes an older version of this product. View Latest

onTabSave()

Registers and calls a callback method when a user clicks Save in a subtab’s Unsaved Changes dialog box. When using this method, you must call setTabUnsavedChanges() in the callback method. This notifies the console that the custom save operation completed. In the call to setTabUnsavedChanges(), pass the first parameter as false to indicate a successful save or true to indicate an unsuccessful save. This method is only available in API version 28.0 or later.

Registering a callback method affects the user interface. When no save handler is registered, the user is presented with two options when closing a tab with unsaved changes: Continue or Cancel. When a save handler is registered, the user is presented with three options when closing the tab: Save, Don’t Save, or Cancel. In this scenario, the callback method registered is called when the user chooses Save.

When using onTabSave() with setTabUnsavedChanges():

  • Note that calling sforce.console.setTabUnsavedChanges(false,...) closes the specified tab. We recommend placing the call to sforce.console.setTabUnsavedChanges() at the end of the callback method, as any subsequent save logic might not execute.
  • Not calling sforce.console.setTabUnsavedChanges() will have a severe affect on the user interface. For example, closing a primary tab with a subtab for which sforce.console.setTabUnsavedChanges() has not been called prevents a Saving... modal dialog box from closing.
  • Any callback passed to sforce.console.setTabUnsavedChanges() will not execute if the specified tab saves successfully and closes.

Important

Calling onTabSave() from a custom console component prevents that component from refreshing when saving the tab. For more information on custom console components, see “Console Components” in the Salesforce online help.

Note

Syntax

1sforce.console.onTabSave(callback:Function)

Arguments

Name Type Description
callback function JavaScript method called to handle the save operation.

Sample Code–Visualforce

1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<apex:page>
18    <A HREF="#" onClick="testOnTabSave();return false">
19         Click here to register save handler</A> 
20    
21    <apex:includeScript value="/support/console/28.0/integration.js"/>
22    <script type="text/javascript">
23        function testOnTabSave() {
24            sforce.console.onTabSave(handleSave);
25        }
26    var handleSave = function handleSave(result) {
27        alert('save handler called from tab with id ' + result.id +
28             ' and objectId ' + result.objectId);
29        //Perform save logic here
30        
31        //Mark tab as 'clean'
32        sforce.console.setTabUnsavedChanges(false, undefined, result.id);
33    };
34  </script>
35</apex:page>
36

Response

Name Type Description
id string ID of the tab being saved.
objectId string Object ID of the tab being saved, if applicable; null otherwise.