When to Use the Salesforce Console Integration Toolkit
Change a Visualforce Page by Using the Salesforce Console Integration Toolkit
addEventListener()
fireEvent()
removeEventListener()
Previous Versions
Adds a listener for a custom event type or a standard event type when the event is fired. This method adds a listener for custom event types in API version 25.0 or later; it adds a listener for standard event types in API version 30.0 or later.
For the list of standard events, see Methods for Console Events.
1sforce.console.addEventListener( eventType: String, eventListener:Function, (optional)additionalParams:Object )| Name | Type | Description |
|---|---|---|
eventType | string | Custom event type for which eventListener listens. |
eventListener | function | JavaScript method called when an eventType is fired. |
additionalParams | object | Optional parameters accepted by this method. The supported properties on this object are tabId: The ID of the tab to listen for the specified event. This argument is only available in API version 30.0 or later. |
1<apex:page>
2 <apex:includeScript value="/support/console/68.0/integration.js"/>
3 <script type="text/javascript">
4
5 var listener = function (result) {
6 alert('Message received from event: ' + result.message);
7 };
8 //Add a listener for the 'SampleEvent' event type
9 sforce.console.addEventListener('SampleEvent', listener);
10 </script>
11</apex:page>This method is asynchronous, so it returns its response in an object in a callback method. The response object contains the following field:
| Name | Type | Description |
|---|---|---|
message | string | The message which is sent with the fired event. If the response is from a custom keyboard shortcut, the message includes the following information on which the browser is focused, in this order:
|
1<apex:page>
2 <apex:includeScript value="/support/console/68.0/integration.js"/>
3 <script type="text/javascript">
4
5 var onEnclosingPrimaryTabClose = function (result) {
6 alert('The enclosing primary tab is about to be closed. Tab ID: ' + result.id + ', Object ID: ' + (result.objectId ? result.objectId : 'not available'));
7 };
8
9 //Add a listener to handle the closing of the enclosing primary tab
10 sforce.console.getEnclosingPrimaryTabId(function (result) {
11 if (result.id) {
12 sforce.console.addEventListener(sforce.console.ConsoleEvent.CLOSE_TAB,
13 onEnclosingPrimaryTabClose, { tabId : result.id });
14 } else {
15 alert('Could not find an enclosing primary TAB!');
16 }
17 });
18 </script>
19</apex:page>This method is asynchronous, so it returns its response in an object in a callback method. The response object contains the following field:
| Name | Type | Description |
|---|---|---|
message | string | The message which is sent with the fired event. If the response is from a console event, the message includes payload details as described in Methods for Console Events. If the response is from a custom keyboard shortcut, the message includes the following information on which the browser is focused, in this order:
|