11.07.2015 Views

Service Cloud Console Integration Toolkit ... - Salesforce.com

Service Cloud Console Integration Toolkit ... - Salesforce.com

Service Cloud Console Integration Toolkit ... - Salesforce.com

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Version 30.0: Spring ’14<strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>Developer's GuideLast updated: February 19, 2014© Copyright 2000–2014 salesforce.<strong>com</strong>, inc. All rights reserved. <strong>Salesforce</strong>.<strong>com</strong> is a registered trademark of salesforce.<strong>com</strong>, inc., as are othernames and marks. Other marks appearing herein may be trademarks of their respective owners.


Table of ContentsTable of ContentsChapter 1: Introducing the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>........................................................1When to Use the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>.........................................................................................................1<strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> Support Policy.............................................................................................................2Backward Compatibility................................................................................................................................................2End-of-Life...................................................................................................................................................................3Other Resources........................................................................................................................................................................3<strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> Typographical Conventions........................................................................................3Sample Visualforce Page Using the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>............................................................................4Chapter 2: Working with the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>.....................................................7Connecting to the <strong>Toolkit</strong>.........................................................................................................................................................7Asynchronous Calls with the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>......................................................................................7Working with Force.<strong>com</strong> Canvas..............................................................................................................................................8Best Practices.............................................................................................................................................................................9Chapter 3: Methods for Primary Tabs and Subtabs...............................................................................10closeTab()................................................................................................................................................................................13focusPrimaryTabById()...........................................................................................................................................................14focusPrimaryTabByName().....................................................................................................................................................15focusSubtabById()...................................................................................................................................................................16focusSubtabByNameAndPrimaryTabId()...............................................................................................................................17focusSubtabByNameAndPrimaryTabName().........................................................................................................................19generate<strong>Console</strong>Url()..............................................................................................................................................................20getEnclosingPrimaryTabId()...................................................................................................................................................21getEnclosingPrimaryTabObjectId()........................................................................................................................................22getEnclosingTabId()...............................................................................................................................................................23getFocusedPrimaryTabId().....................................................................................................................................................24getFocusedPrimaryTabObjectId()...........................................................................................................................................25getFocusedSubtabId()..............................................................................................................................................................26getFocusedSubtabObjectId()...................................................................................................................................................26getPageInfo()...........................................................................................................................................................................27getPrimaryTabIds().................................................................................................................................................................28getSubtabIds().........................................................................................................................................................................29getTabLink()...........................................................................................................................................................................30isIn<strong>Console</strong>()...........................................................................................................................................................................31onEnclosingTabRefresh().......................................................................................................................................................32onFocusedSubtab()..................................................................................................................................................................33onTabSave()............................................................................................................................................................................34open<strong>Console</strong>Url()....................................................................................................................................................................35openPrimaryTab()...................................................................................................................................................................36openSubtab()...........................................................................................................................................................................38openSubtabByPrimaryTabName()..........................................................................................................................................39refreshPrimaryTabById()........................................................................................................................................................41i


Table of ContentsrefreshPrimaryTabByName()..................................................................................................................................................42refreshSubtabById()................................................................................................................................................................43refreshSubtabByNameAndPrimaryTabId()............................................................................................................................45refreshSubtabByNameAndPrimaryTabName()......................................................................................................................46resetSessionTimeOut()............................................................................................................................................................47setTabUnsavedChanges()........................................................................................................................................................48setTabIcon()............................................................................................................................................................................49setTabLink()............................................................................................................................................................................51setTabStyle()...........................................................................................................................................................................51setTabTextStyle()....................................................................................................................................................................52setTabTitle()...........................................................................................................................................................................54Chapter 4: Methods for Computer-Telephony <strong>Integration</strong> (CTI).........................................................56getCallAttachedData()............................................................................................................................................................56getCallObjectIds()...................................................................................................................................................................57onCallBegin()..........................................................................................................................................................................58onCallEnd()............................................................................................................................................................................59sendCTIMessage()..................................................................................................................................................................60Chapter 5: Methods for Application-Level Custom <strong>Console</strong> Components............................................62addToBrowserTitleQueue()....................................................................................................................................................63blinkCustom<strong>Console</strong>ComponentButtonText()......................................................................................................................64isCustom<strong>Console</strong>ComponentPoppedOut()............................................................................................................................65isCustom<strong>Console</strong>ComponentWindowHidden()....................................................................................................................66isInCustom<strong>Console</strong>Component()...........................................................................................................................................67onCustom<strong>Console</strong>ComponentButtonClicked()......................................................................................................................68onFocusedPrimaryTab()..........................................................................................................................................................69removeFromBrowserTitleQueue()..........................................................................................................................................69scrollCustom<strong>Console</strong>ComponentButtonText()......................................................................................................................70setCustom<strong>Console</strong>ComponentButtonIconUrl().....................................................................................................................71setCustom<strong>Console</strong>ComponentButtonStyle()..........................................................................................................................72setCustom<strong>Console</strong>ComponentButtonText()..........................................................................................................................73setCustom<strong>Console</strong>ComponentPopoutable()...........................................................................................................................74setCustom<strong>Console</strong>ComponentWindowVisible()....................................................................................................................75Chapter 6: Methods for Push Notifications..........................................................................................77addPushNotificationListener()................................................................................................................................................78removePushNotificationListener()..........................................................................................................................................79Chapter 7: Methods for <strong>Console</strong> Events..............................................................................................81addEventListener()..................................................................................................................................................................81fireEvent()...............................................................................................................................................................................83removeEventListener()............................................................................................................................................................84Chapter 8: Methods for Live Agent.....................................................................................................86acceptChat()............................................................................................................................................................................88ii


Table of ContentsdeclineChat()...........................................................................................................................................................................89endChat()................................................................................................................................................................................90getAgentInput()......................................................................................................................................................................91getAgentState().......................................................................................................................................................................92getChatLog()...........................................................................................................................................................................93getChatRequests()...................................................................................................................................................................94getDetailsByChatKey()...........................................................................................................................................................95getDetailsByPrimaryTabId()...................................................................................................................................................99getEngagedChats()................................................................................................................................................................102getMaxCapacity()..................................................................................................................................................................103onAgentSend()......................................................................................................................................................................104onAgentStateChanged()........................................................................................................................................................105onChatCanceled().................................................................................................................................................................106onChatCriticalWaitState()....................................................................................................................................................106onChatDeclined()..................................................................................................................................................................107onChatEnded().....................................................................................................................................................................108onChatRequested()...............................................................................................................................................................109onChatStarted().....................................................................................................................................................................109onChatTransferredOut().......................................................................................................................................................110onCurrentCapacityChanged()...............................................................................................................................................111onCustomEvent()..................................................................................................................................................................112onNewMessage()...................................................................................................................................................................113onTypingUpdate().................................................................................................................................................................114sendCustomEvent()...............................................................................................................................................................115sendMessage().......................................................................................................................................................................116setAgentInput().....................................................................................................................................................................117setAgentState()......................................................................................................................................................................118Methods for Live Agent Chat Visitors..................................................................................................................................119chasitor.addCustomEventListener()..........................................................................................................................119chasitor.getCustomEvents()......................................................................................................................................120chasitor.sendCustomEvent().....................................................................................................................................121Glossary...........................................................................................................................................123Index...............................................................................................................................................129iii


Chapter 1Introducing the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>The <strong>Salesforce</strong> console is designed for users in fast-paced environments who need to find, update, and create records in<strong>Salesforce</strong> quickly. The <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> provides you with programmatic access to the <strong>Salesforce</strong> consoleso that you can extend it to meet your business needs. With the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>, you can open andclose tabs in the console to streamline a business process. For example, the toolkit lets you integrate third-party systems withthe console, opening up an external application in the same window, in a tab. To use this guide, you should have a basicfamiliarity with:• JavaScript• Visualforce• Web services• Software development• The <strong>Salesforce</strong> consoleThis guide explains how to use the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> in JavaScript to embed API calls and processes.The toolkit is available for use with third-party domains, such as www.yourdomain.<strong>com</strong>; however, the examples in this guideare in Visualforce. The functionality it describes is available to your organization if you have:• Enterprise, Unlimited, Performance, or Developer Edition with the <strong>Service</strong> <strong>Cloud</strong>• The <strong>Salesforce</strong> consoleThe <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> is a browser-based JavaScript API. It uses browsers as clients to display pages astabs in the console. The <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>:• Matches the API version for any given release. For example, if the current version of SOAP API is 20.0, then there's alsoa version 20.0 of the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>.• Supports any browser that the <strong>Salesforce</strong> console supports. For more information, see “<strong>Salesforce</strong> <strong>Console</strong> Overview” inthe <strong>Salesforce</strong> online help.Note: To enable the toolkit for third-party domains, you must add the domains to the whitelist of the <strong>Salesforce</strong>console. See “Whitelist Domains for a <strong>Salesforce</strong> <strong>Console</strong>” in the <strong>Salesforce</strong> online help.When to Use the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>The <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> helps advanced administrators and developers implement custom functionalityfor the <strong>Salesforce</strong> console. For example, you can use the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> to display Visualforce pagesor third-party content as tabs in the <strong>Salesforce</strong> console. The <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> is an API that uses browsersas clients to display pages in the console.The following table lists additional features that developers can use to implement custom functionality for <strong>Salesforce</strong>organizations.1


Introducing the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong><strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> Support PolicyFeatureSOAP APIDescriptionUse standard SOAP API calls if you want to add functionality to a <strong>com</strong>posite application thatprocesses only one type of record at a time and does not require any transactional control (suchas setting a Savepoint or rolling back changes).For more information, see the SOAP API Developer's Guide.VisualforceVisualforce consists of a tag-based markup language that gives developers a more powerfulway of building applications and customizing the <strong>Salesforce</strong> user interface. With Visualforceyou can:• Build wizards and other multistep processes.• Create your own custom flow control through an application.• Define navigation patterns and data-specific rules for optimal, efficient applicationinteraction.For more information, see the Visualforce Developer's Guide.ApexUse Apex if you want to:• Create Web services.• Create email services.• Perform <strong>com</strong>plex validation over multiple objects.• Create <strong>com</strong>plex business processes that are not supported by workflow.• Create custom transactional logic (logic that occurs over the entire transaction, not justwith a single record or object).• Attach custom logic to another operation, such as saving a record, so that it occurs wheneverthe operation is executed, regardless of whether it originates in the user interface, aVisualforce page, or from SOAP API.For more information, see the Force.<strong>com</strong> Apex Code Developer's Guide.<strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> Support PolicyThe current release of the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> is the only version that receives enhancements. Previousversions may or may not receive fixes. When a new version is released, the previous version remains available.Backward Compatibility<strong>Salesforce</strong>.<strong>com</strong> strives to make backward <strong>com</strong>patibility easy when using the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>.Each new <strong>Salesforce</strong> release consists of two <strong>com</strong>ponents:• A new release of platform software that resides on salesforce.<strong>com</strong> systems• A new version of the APIFor example, the Summer '10 release included API version 19.0 and the Winter ’11 release included API version 20.0.The version of the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> matches the API version for any given release. So if the currentversion of the API is 20.0, there's also a version 20.0 of the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>.2


Introducing the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>End-of-LifeWe maintain support for each <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> version across releases of the platform. The <strong>Salesforce</strong><strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> is backward <strong>com</strong>patible in that an application created to work with a given <strong>Salesforce</strong> <strong>Console</strong><strong>Integration</strong> <strong>Toolkit</strong> version will continue to work with that same <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> version in futureplatform releases.<strong>Salesforce</strong>.<strong>com</strong> doesn't guarantee that an application written against one <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> version willwork with future <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> versions: Changes in method signatures and data representations areoften required as we continue to enhance the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>. However, we strive to keep the <strong>Salesforce</strong><strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> consistent from version to version with minimal changes required to port applications to newer<strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> versions.For example, an application written using <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> version 20.0, which shipped with the Winter’11 release, will continue to work with <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> version 20.0 on the Summer ’11 release and onfuture releases. However, that same application may not work with <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> version 21.0 withoutmodifications to the application.End-of-Life<strong>Salesforce</strong>.<strong>com</strong> is <strong>com</strong>mitted to supporting each <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> version for a minimum of three yearsfrom the date of its first release. To improve the quality and performance of the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>,versions that are more than three years old may not be supported.When a <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> version is scheduled to be unsupported, an advance end-of-life notice will begiven at least one year before support for the version ends. <strong>Salesforce</strong>.<strong>com</strong> will directly notify customers using <strong>Salesforce</strong><strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> versions scheduled for end of life.Other ResourcesIn addition to this guide, there are other resources available for you as you learn how to use the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong><strong>Toolkit</strong>:• Online help: See <strong>Salesforce</strong> <strong>Console</strong> Overview• Developer website: http://developer.force.<strong>com</strong>/gettingstarted• Firebug extension to Firefox: Firebug for Firefox• Eclipse plug-in: Force.<strong>com</strong> IDENote: <strong>Salesforce</strong>.<strong>com</strong> Education <strong>Service</strong>s offers a suite of training courses to enable developers to design, create,integrate, and extend applications built on the Force.<strong>com</strong> platform. Be sure to visit http://www.salesforce.<strong>com</strong>/trainingto learn more.<strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> TypographicalConventionsThe <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> guide uses the following typographical conventions:ConventionCourier fontDescriptionIn descriptions of syntax, monospace font indicates items that you should type as shown,except for brackets. For example:Public class HelloWorld3


Introducing the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>Sample Visualforce Page Using the <strong>Salesforce</strong> <strong>Console</strong><strong>Integration</strong> <strong>Toolkit</strong>ConventionItalicsDescriptionIn descriptions of syntax, italics represent variables. You supply the actual value. In thefollowing example, three values need to be supplied: datatype variable_name [ =value];If the syntax is bold and italic, the text represents a code element that needs a valuesupplied by you, such as a class name or variable value:public static class YourClassHere { ... }Bold Courier font< >In code samples and syntax descriptions, bold courier font emphasizes a portion of thecode or syntax.In descriptions of syntax, less-than and greater-than symbols (< >) are typed exactly asshown.{ }In descriptions of syntax, braces ({ }) are typed exactly as shown.Hello {!$User.FirstName}![ ]In descriptions of syntax, anything included in brackets is optional. In the followingexample, specifying value is optional:data_type variable_name [ = value];|In descriptions of syntax, the pipe sign means “or”. You can do one of the following(not all). In the following example, you can create a new unpopulated set in one of twoways, or you can populate the set:Set set_name[= new Set();] |[= new Set


Introducing the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>Sample Visualforce Page Using the <strong>Salesforce</strong> <strong>Console</strong><strong>Integration</strong> <strong>Toolkit</strong>This code demonstrates various functions of the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>:function openPrimaryTab() {sforce.console.openPrimaryTab(undefined,'http://www.salesforce.<strong>com</strong>', true, 'salesforce');}//The callback function that openSubtab will call once it's got the ID for itsprimary tabvar callOpenSubtab=function callOpenSubtab(result) {sforce.console.openSubtab(result.id,'http://www.yahoo.<strong>com</strong>', true, 'yahoo');};function openSubtab() {sforce.console.getEnclosingPrimaryTabId(callOpenSubtab);}//Sets the title of the current tab to "SFDC"function setTitle() {sforce.console.setTabTitle('SFDC');}//The callback function that closeTab will call once it's got the ID for its tabvar callCloseTab= function callCloseTab(result) {sforce.console.closeTab(result.id);}function closeTab() {sforce.console.getEnclosingTabId(callCloseTab);}Open A Primary TabOpen A SubtabSet Title to SFDCClose This TabNote: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.After you create the above Visualforce page and add it as a custom link on cases, this page displays after you navigate to a caseand click the link:5


Introducing the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>Sample Visualforce Page Using the <strong>Salesforce</strong> <strong>Console</strong><strong>Integration</strong> <strong>Toolkit</strong>Figure 1: Output of Sample Visualforce Page6


Chapter 2Working with the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>Use the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> to do the following in the <strong>Salesforce</strong> console:• Open a new primary tab or subtab that displays a specified URL• Set the title of a primary tab or a subtab• Return the ID of a primary tab or subtab• Close a specified primary tab or subtabConnecting to the <strong>Toolkit</strong>The first portion of any JavaScript code that uses the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> must make the toolkit availableto the JavaScript code. The syntax for this is different depending on whether you are embedding JavaScript in a Visualforcepage, or a third-party domain.• For Visualforce pages or any source other than a custom onclick JavaScript button, specify a tag that pointsto the toolkit file:...For Visualforce, a relative path is sufficient to include integration.js, and is re<strong>com</strong>mended.• For a third-party domain:For third-party domains, it is necessary to specify an absolute URL to integration.js to use the toolkit. The defaultinstance at which you can access the toolkit library is:c.na1.visual.force.<strong>com</strong>/support/console/30.0/integration.js. We re<strong>com</strong>mend that you use the defaultinstance when the organization’s instance cannot be determined.The version of the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> is in the URL.Asynchronous Calls with the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong><strong>Toolkit</strong>The <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> lets you issue asynchronous calls. Asynchronous calls allow the client-side processto continue instead of waiting for a callback from the server. To issue an asynchronous call, you must include an additional7


Working with the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>Working with Force.<strong>com</strong> Canvasparameter with the API call, which is referred to as a callback function. Once the result is ready, the server invokes the callbackmethod with the result.Asynchronous syntax:method('arg1','arg2', ..., callback_method);For example://Open a new primary tab with the <strong>Salesforce</strong> home page in itsforce.console.openPrimaryTab(null, 'http://www.salesforce.<strong>com</strong>',false, '<strong>Salesforce</strong>', callback);Working with Force.<strong>com</strong> CanvasTo integrate the <strong>Salesforce</strong> <strong>Console</strong> with external applications that require authentication methods, such as signed requestsor OAuth 2.0 protocols, <strong>Salesforce</strong>.<strong>com</strong> re<strong>com</strong>mends you use Force.<strong>com</strong> Canvas.Force.<strong>com</strong> Canvas and the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> are similar—they’re a set of tools and JavaScript APIs thatdevelopers can use to add third-party systems to <strong>Salesforce</strong>. However, one of the benefits of Force.<strong>com</strong> Canvas, is the abilityto choose authentication methods. For more information, see the Force.<strong>com</strong> Canvas Developer’s Guide.Note: For a canvas app to appear in a console, you must add it to the console as a custom console <strong>com</strong>ponent. See“Adding Custom <strong>Console</strong> Components” in the <strong>Salesforce</strong> Help.When developing a canvas app, and you want to include functionality from the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>, dothe following:1. Include the console integration toolkit API in index.jsp.2. If your console has a whitelist for domains, add the domain of your canvas app to the whitelist. See “Whitelist Domainsfor a <strong>Salesforce</strong> <strong>Console</strong>” in the <strong>Salesforce</strong> Help.3. Call Sfdc.canvas.client.signedrequest() to store the signed request needed by the console integration toolkitAPI. For example, if the Force.<strong>com</strong> Canvas method of authentication is a signed request, do the following:Sfdc.canvas.client.signedrequest('')If the Force.<strong>com</strong> Canvas method of authentication is OAuth, do the following in the callback function used to get thecontext as shown in “Getting Context in Your Canvas App” in the Force.<strong>com</strong> Canvas Developer’s Guide:Sfdc.canvas.client.signedrequest(msg)Consider the following when working with the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> and canvas apps:• The console integration toolkit API script depends on the signed request and should be added after the call toSfdc.canvas.client.signedrequest() has executed. We re<strong>com</strong>mend that you load the scripts dynamically.• To retrieve the entity ID of the record that is associated with the canvas sidebar <strong>com</strong>ponent, do the following:// Get signedRequestvar signedRequest = Sfdc.canvas.client.signedrequest();var parsedRequest = JSON.parse(signedRequest);// get the entity Id that is associated with this canvas sidebar <strong>com</strong>ponent.var entityId = parsedRequest.context.environment.parameters.entityId;8


Working with the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>Best Practices• To retrieve the entityId for OAuth, do the following:var entityId = msg.payload.environment.parameters.entityId;To see an example on how to retrieve msg.payload, see “Getting Context in Your Canvas App” in the Force.<strong>com</strong> CanvasDeveloper’s Guide.Best Practices• Since many of the methods in the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> are asynchronous and return their results usinga callback method, <strong>Salesforce</strong>.<strong>com</strong> re<strong>com</strong>mends that you refer to the documentation for each method to understand theinformation for each response.• Errors generated by the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> are typically emitted in a way that doesn't halt JavaScriptprocessing. Therefore, <strong>Salesforce</strong> re<strong>com</strong>mends you use a tool such as Firebug for Firefox to monitor the JavaScript consoleand to help you debug your code.• To display Visualforce pages properly in the <strong>Salesforce</strong> <strong>Console</strong>, <strong>Salesforce</strong>.<strong>com</strong> re<strong>com</strong>mends you:◊◊Set showHeader="false" and sidebar="false" on the apex:page tag.Set Behavior on custom buttons and links that include methods from the toolkit to display in an existing windowwithout a sidebar or header. For more information, see Defining Custom Buttons and Links” in the <strong>Salesforce</strong> onlinehelp.• When using Firefox, <strong>Salesforce</strong>.<strong>com</strong> re<strong>com</strong>mends that you don't call closeTab() on a tab with an active alert box becausethe browser may not load properly.• Duplicate tabs might open when users initiate methods with invalid URLs. <strong>Salesforce</strong>.<strong>com</strong> re<strong>com</strong>mends you check URLsfor validity before you include them in methods.• To prevent External Page from displaying as a tab name, <strong>Salesforce</strong> re<strong>com</strong>mends you specify the tabLabel argumenton methods such as openPrimaryTab() and openSubtab().• For information on how you can customize, extend, or integrate the sidebars of the <strong>Salesforce</strong> console using Visualforce,<strong>Salesforce</strong>.<strong>com</strong> re<strong>com</strong>mends you see “Custom <strong>Console</strong> Components Overview” in the <strong>Salesforce</strong> online help.• To enable the toolkit for third-party domains, you must add the domains to the whitelist of the <strong>Salesforce</strong> console. See“Whitelist Domains for a <strong>Salesforce</strong> <strong>Console</strong>” in the <strong>Salesforce</strong> online help.9


Chapter 3Methods for Primary Tabs and SubtabsThe <strong>Salesforce</strong> console displays <strong>Salesforce</strong> pages as primary tabs or subtabs:Primary TabSubtabA tab in a <strong>Salesforce</strong> console that displays the main item to work on, such as an account.A tab that displays content related to the item on a primary tab in a <strong>Salesforce</strong> console. For example, a primary tabshowing an account might have subtabs for cases and contacts.You can use the following methods for primary tabs and subtabs:MethodcloseTab()focusPrimaryTabById()focusPrimaryTabByName()focusSubtabById()focusSubtabByNameAndPrimaryTabId()focusSubtabByNameAndPrimaryTabName()generate<strong>Console</strong>Url()DescriptionCloses a specified primary tab or subtab. Note that closing the firsttab in a primary tab closes the primary tab itself. This method isonly available in API version 20.0 or later.Focuses the browser on a primary tab that is already open with thespecified ID. This method is only available in API version 22.0 orlater.Focuses the browser on a primary tab that is already open with thespecified name. This method is only available in API version 22.0or later.Focuses the browser on a subtab that is already open with thespecified ID. This method is only available in API version 22.0 orlater.Focuses the browser on a subtab that is already open with thespecified name and primary tab ID. This method is only availablein API version 22.0 or later.Focuses the browser on a subtab that is already open with thespecified name and primary tab name. This method is only availablein API version 22.0 or later.Generates a URL to a tab, or group of related tabs, in the <strong>Salesforce</strong>console. If any tabs include external URLs, then add the externalURLs to the console’s whitelist so that they can display correctly.For more information, see “Whitelist Domains for a <strong>Salesforce</strong><strong>Console</strong>” in the online help. This method is only available in APIversion 28.0 or later.10


Methods for Primary Tabs and SubtabsMethodgetEnclosingPrimaryTabId()getEnclosingPrimaryTabObjectId()getEnclosingTabId()getFocusedPrimaryTabId()getFocusedPrimaryTabObjectId()getFocusedSubtabId()getFocusedSubtabObjectId()getPageInfo()getPrimaryTabIds()getSubtabIds()getTabLink()isIn<strong>Console</strong>()onEnclosingTabRefresh()DescriptionReturns the ID of the current primary tab. This method workswithin a primary tab or subtab, not within the navigation tab orcustom console <strong>com</strong>ponents. This method is only available in APIversion 20.0 or later.Returns the object ID of the current primary tab, which containsa subtab. For example, a case ID or account ID. This method workswithin a primary tab or subtab. This method is only available inAPI version 24.0 or later.Returns the ID of the tab that contains the current Visualforcepage, which may be a primary tab or subtab. This method will workif the call is made within a <strong>com</strong>ponent enclosed within a subtab.This method is only available in API version 20.0 or later.Returns the ID of the primary tab on which the browser is focused.This method is only available in API version 25.0 or later.Returns the object ID of the primary tab on which the browser isfocused. This method is only available in API version 25.0 or later.Returns the ID of the subtab on which the browser is focused. Forexample, a case ID or account ID. This method is only availablein API version 25.0 or later.Returns the object ID of the subtab on which the browser isfocused. For example, a case ID or account ID. This method isonly available in API version 24.0 or later.Returns page information for the specified tab after its content hasloaded. If the tab ID is null, it returns page information for theenclosing primary tab or subtab. Note that to get the pageinformation from a custom console <strong>com</strong>ponent, a tabId must bepassed as the first parameter to this method.This method is onlyavailable in API version 26.0 or later.Returns all of the IDs of open primary tabs. This method is onlyavailable in API version 26.0 or later.Returns all of the IDs of the subtabs on the primary tab specifiedby a primary tab ID. If the primary tab ID is null, it returns theIDs of the subtabs on the current primary tab. This method canonly be called from a custom console <strong>com</strong>ponent or a detail pageoverwritten by a Visualforce page. This method is only available inAPI version 26.0 or later.Retrieves the URL to a tab, or group of related tabs, from the<strong>Salesforce</strong> console. This method is only available in API version28.0 or later.Determines if the page is in the <strong>Salesforce</strong> console. This methodis only available in API version 22.0 or later.Registers a function to call when the enclosing tab refreshes. Thismethod is only available in API version 24.0 or later.11


Methods for Primary Tabs and SubtabsMethodonFocusedSubtab()onTabSave()open<strong>Console</strong>Url()openPrimaryTab()openSubtab()openSubtabByPrimaryTabName()refreshPrimaryTabById()refreshPrimaryTabByName()refreshSubtabById()refreshSubtabByNameAndPrimaryTabId()DescriptionRegisters a function to call when the focus of the browser changesto a different subtab. This method is only available in API version24.0 or later.Registers and calls a callback method when a user clicks Save in asubtab’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 <strong>com</strong>pleted.In the call to setTabUnsavedChanges(), pass the first parameteras false to indicate a successful save or true to indicate anunsuccessful save. This method is only available in API version28.0 or later.Opens a URL created by the generate<strong>Console</strong>Url() method(a URL to a tab, or group of related tabs, in the <strong>Salesforce</strong> console).This method is only available in API version 28.0 or later.Opens a new primary tab to display the content of the specifiedURL, which can be relative or absolute. You can also override anexisting tab. This method is only available in API version 20.0 orlater.Opens a new subtab (within a primary tab) that displays the contentof a specified URL, which can be relative or absolute. You can alsooverride an existing subtab. Use to open a new subtab on a primarytab via the primary tab's ID. This method is only available in APIversion 20.0 or later.Opens a new subtab (within a primary tab) that displays the contentof a specified URL, which can be relative or absolute. You can alsooverride an existing subtab. Use to open a new subtab on a primarytab via the primary tab's name. This method is only available inAPI version 22.0 or later.Refreshes a primary tab specified by ID, including its subtabs. Thismethod can't refresh subtabs with URLs to external pages orVisualforce pages. This method is only available in API version22.0 or later.Refreshes a primary tab specified by name, including its subtabs.This method can't refresh subtabs with URLs to external pages orVisualforce pages. This method is only available in API version22.0 or later.Refreshes a subtab with the last known URL with a specified ID.This method can't refresh a subtab If the last known URL is anexternal page or a Visualforce page. This method is only availablein API version 22.0 or later.Refreshes a subtab with the last known URL with the specifiedname and primary tab ID. This method can't refresh a subtab Ifthe last known URL is an external page or a Visualforce page. Thismethod is only available in API version 22.0 or later.12


Methods for Primary Tabs and SubtabscloseTab()MethodrefreshSubtabByNameAndPrimaryTabName()resetSessionTimeOut()setTabLink()setTabIcon()setTabStyle()setTabTextStyle()setTabTitle()setTabUnsavedChanges()DescriptionRefreshes a subtab with the last known URL with the specifiedname and primary tab name. This method can't refresh a subtab Ifthe last known URL is an external page or a Visualforce page. Thismethod is only available in API version 22.0 or later.Resets a session timeout on a Visualforce page so that users cancontinue working without being logged out. For more information,see “Setting Session Security” in the <strong>Salesforce</strong> Help. This methodis only available in API version 24.0 or later.Sets a console tab’s URL attribute to the location of the tab’scontent. Use this method to generate secure console URLs whenusers navigate to tabs displaying content outside of the <strong>Salesforce</strong>domain.This method is only available in API version 28.0 or later.Sets an icon on the specified tab. If a tab is not specified, the iconis set on the enclosing tab. Use this method to customize a tab’sicon. This method is only available in API version 28.0 or later.Sets a cascading style sheet (CSS) on the specified tab. If a tab isnot specified, the CSS is set on the enclosing tab. Use this methodto customize a tab’s look and feel. This method is only available inAPI version 28.0 or later.Sets a cascading style sheet (CSS) on a specified tab’s text. If a tabis not specified, the CSS is set on the enclosing tab’s text. Use thismethod to customize a tab’s text style. This method is only availablein API version 28.0 or later.Sets the title of a primary tab or subtab. This method is onlyavailable in API version 20.0 or later.Sets the unsaved changes icon ( ) on subtabs to indicate unsaveddata. This method is only available in API version 23.0 or later.closeTab()UsageCloses a specified primary tab or subtab. Note that closing the first tab in a primary tab closes the primary tab itself. Thismethod is only available in API version 20.0 or later.Syntaxsforce.console.closeTab(id:String)ArgumentsNameidTypestringDescriptionID of the primary tab or subtab to close.13


Methods for Primary Tabs and SubtabsfocusPrimaryTabById()Sample Code–VisualforceClick here to close this tabfunction testCloseTab() {//First find the ID of the current tab to close itsforce.console.getEnclosingTabId(closeSubtab);}var closeSubtab = function closeSubtab(result) {//Now that we have the tab ID, we can close itvar tabId = result.id;sforce.console.closeTab(tabId);};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseNoneTip: When using Firefox, <strong>Salesforce</strong>.<strong>com</strong> re<strong>com</strong>mends that you don't call closeTab() on a tab with an active alertbox because the browser may not load properly.focusPrimaryTabById()UsageFocuses the browser on a primary tab that is already open with the specified ID. This method is only available in API version22.0 or later.Syntaxsforce.console.focusPrimaryTabById(id:String, (optional)callback:Function)ArgumentsNameidcallbackTypestringfunctionDescriptionID of the primary tab to go to.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to go to an open primary tab by id14


Methods for Primary Tabs and SubtabsfocusPrimaryTabByName()function testFocusPrimaryTabById() {//Get the value for 'scc-pt-0' from the openPrimaryTab method//This value is for example purposes onlyvar primaryTabId = 'scc-pt-0';sforce.console.focusPrimaryTabById(primaryTabId, focusSuccess);}var focusSuccess = function focusSuccess(result) {//Report whether going to the open primary tab was successfulif (result.success == true) {alert('Going to the primary tab was successful');} else {alert('Going to the primary tab was not successful');}};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if going to the primary tab was successful; false if going to the primarytab wasn't successful.focusPrimaryTabByName()UsageFocuses the browser on a primary tab that is already open with the specified name. This method is only available in API version22.0 or later.Syntaxsforce.console.focusPrimaryTabByName(name:String, (optional)callback:Function)ArgumentsNamenamecallbackTypestringfunctionDescriptionName of the primary tab to go to.JavaScript method called upon <strong>com</strong>pletion of the method.15


Methods for Primary Tabs and SubtabsfocusSubtabById()Sample Code–VisualforceClick here to go to a primary tab by namefunction testFocusPrimaryTabByName() {//Get the value for 'myPrimaryTab' from the openPrimaryTab method//This value is for example purposes onlyvar primaryTabName = 'myPrimaryTab';sforce.console.focusPrimaryTabByName(primaryTabName, focusSuccess);}var focusSuccess = function focusSuccess(result) {//Report whether going to the primary tab was successfulif (result.success == true) {alert('Going to the primary tab was successful');} else {alert('Going to the Primary tab was not successful');}};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if going to the primary tab was successful; false if going to the primarytab wasn't successful.focusSubtabById()UsageFocuses the browser on a subtab that is already open with the specified ID. This method is only available in API version 22.0or later.Syntaxsforce.console.focusSubtabById(id:String, (optional)callback:Function)16


Methods for Primary Tabs and SubtabsfocusSubtabByNameAndPrimaryTabId()ArgumentsNameidcallbackTypestringfunctionDescriptionID of the subtab to go to.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to go to a subtab by idfunction testFocusSubtabById() {//Get the value for 'scc-st-0' from the openSubtab method//This value is for example purposes onlyvar subtabId = 'scc-st-0';sforce.console.focusSubtabById(subtabId, focusSuccess);}var focusSuccess = function focusSuccess(result) {//Report whether going to the subtab was successfulif (result.success == true) {alert('Going to the subtab was successful');} else {alert('Going to the subtab was not successful');}};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if going to the subtab was successful; false if going to the subtab wasn'tsuccessful.focusSubtabByNameAndPrimaryTabId()UsageFocuses the browser on a subtab that is already open with the specified name and primary tab ID. This method is only availablein API version 22.0 or later.17


Methods for Primary Tabs and SubtabsfocusSubtabByNameAndPrimaryTabId()Syntaxsforce.console.focusSubtabByNameAndPrimaryTabId(name:String,primaryTabId:String,(optional)callback:Function)ArgumentsNamenameprimaryTabIdcallbackTypestringstringfunctionDescriptionName of the subtab to go to.ID of the primary tab in which the subtab opened.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to go to a subtab by name and primary tab IDfunction testFocusSubtabByNameAndPrimaryTabId() {//Get the values for 'mySubtab' and 'scc-pt-0' from the openSubtab method//These values are for example purposes onlyvar subtabName = 'mySubtab';var primaryTabId = 'scc-pt-0';sforce.console.focusSubtabByNameAndPrimaryTabId(subtabName, primaryTabId,focusSuccess);}var focusSuccess = function focusSuccess(result) {//Report whether going to the subtab was successfulif (result.success == true) {alert('Going to the subtab was successful');} else {alert('Going to the subtab was not successful');}};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if going to the subtab was successful; false if going to the subtab wasn'tsuccessful.18


Methods for Primary Tabs and SubtabsfocusSubtabByNameAndPrimaryTabName()focusSubtabByNameAndPrimaryTabName()UsageFocuses the browser on a subtab that is already open with the specified name and primary tab name. This method is onlyavailable in API version 22.0 or later.Syntaxsforce.console.focusSubtabByNameAndPrimaryTabName(name:String,primaryTabName:String,(optional)callback:Function)ArgumentsNamenameprimaryTabNamecallbackTypestringstringfunctionDescriptionName of the subtab to go to.Name of the primary tab in which the subtab opened.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to go to a subtab by name and primary tab namefunction testFocusSubtabByNameAndPrimaryTabName() {//Get the value for 'mySubtab' and 'myPrimaryTab' from the openSubtab method//These values are for example purposes onlyvar subtabName = 'mySubtab';var primaryTabName = 'myPrimaryTab';sforce.console.focusSubtabByNameAndPrimaryTabName(subtabName, primaryTabName,focusSuccess);}var focusSuccess = function focusSuccess(result) {//Report whether going to the subtab was successfulif (result.success == true) {alert('Going to the subtab was successful');} else {alert('Going to the subtab was not successful');}};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.19


Methods for Primary Tabs and SubtabsgetEnclosingPrimaryTabId()NameconsoleUrlsuccesscallbackTypestringbooleanfunctionDescription<strong>Console</strong> URL that represents the array of URLs passed into <strong>Salesforce</strong>.true if the URL was generated successfully, false if otherwise.JavaScript method called upon <strong>com</strong>pletion of the method.getEnclosingPrimaryTabId()UsageReturns the ID of the current primary tab. This method works within a primary tab or subtab, not within the navigation tabor custom console <strong>com</strong>ponents. This method is only available in API version 20.0 or later.Syntaxsforce.console.getEnclosingPrimaryTabId((optional)callback:function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to close this primary tabfunction testCloseTab() {//First find the ID of the current primary tab to close itsforce.console.getEnclosingPrimaryTabId(closeSubtab);}var closeSubtab = function closeSubtab(result) {//Now that we have the primary tab ID, we can close itvar tabId = result.id;sforce.console.closeTab(tabId);};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:21


Methods for Primary Tabs and SubtabsgetEnclosingPrimaryTabObjectId()NameidTypestringDescriptionThe ID of the current primary tab that contains this tab.getEnclosingPrimaryTabObjectId()UsageReturns the object ID of the current primary tab, which contains a subtab. For example, a case ID or account ID. This methodworks within a primary tab or subtab. This method is only available in API version 24.0 or later.Syntaxsforce.console.getEnclosingPrimaryTabObjectId((optional)callback:Function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to get enclosing primary tab object IDfunction testGetEnclosingPrimaryTabObjectId() {sforce.console.getEnclosingPrimaryTabObjectId(showObjectId);}var showObjectId = function showObjectId(result) {// Display the object IDalert ('Object ID: ' + result.id);};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NameidsuccessTypestringbooleanDescriptionThe ID of the current primary tab that contains this subtab.true if returning the enclosing primary tab was successful; false if returningthe enclosing primary tab wasn't successful.22


Methods for Primary Tabs and SubtabsgetEnclosingTabId()getEnclosingTabId()UsageReturns the ID of the tab that contains the current Visualforce page, which may be a primary tab or subtab. This method willwork if the call is made within a <strong>com</strong>ponent enclosed within a subtab. This method is only available in API version 20.0 orlater.Syntaxsforce.console.getEnclosingTabId()ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to close this tabfunction testCloseTab() {//First find the ID of the current tab to close itsforce.console.getEnclosingTabId(closeSubtab);}var closeSubtab = function closeSubtab(result) {//Now that we have the tab ID, we can close itvar tabId = result.id;sforce.console.closeTab(tabId);};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NameidTypestringDescriptionThe ID of the current primary tab or subtab.23


Methods for Primary Tabs and SubtabsgetFocusedPrimaryTabId()getFocusedPrimaryTabId()UsageReturns the ID of the primary tab on which the browser is focused. This method is only available in API version 25.0 or later.Syntaxsforce.console.getFocusedPrimaryTabId((optional) callback:Function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to get the focused primary tab IDfunction testGetFocusedPrimaryTabId() {sforce.console.getFocusedPrimaryTabId(showTabId);}var showTabId = function showTabId(result) {//Display the tab IDalert('Tab ID: ' + result.id);};ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NameidsuccessTypestringbooleanDescriptionThe ID of the primary tab on which the browser is focused. If no primary tabis open, the ID is null.true if returning the primary tab ID on which the browser is focused wassuccessful; false if returning the primary tab ID on which the browser isfocused wasn't successful.24


Methods for Primary Tabs and SubtabsgetFocusedPrimaryTabObjectId()getFocusedPrimaryTabObjectId()UsageReturns the object ID of the primary tab on which the browser is focused. This method is only available in API version 25.0or later.Syntaxsforce.console.getFocusedPrimaryTabObjectId((optional) callback:Function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to get the focused primary tab object IDfunction testGetFocusedPrimaryTabObjectId() {sforce.console.getFocusedPrimaryTabObjectId(showObjectId);}var showObjectId = function showObjectId(result) {//Display the object IDalert('Object ID: ' + result.id);};ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NameidsuccessTypestringbooleanDescriptionThe object ID of the primary tab on which the browser is focused. If there isno primary tab open, the ID is null.true if returning the primary tab object ID on which the browser is focusedwas successful; false if returning the primary tab object ID on which thebrowser is focused wasn't successful.25


Methods for Primary Tabs and SubtabsgetFocusedSubtabId()getFocusedSubtabId()UsageReturns the ID of the subtab on which the browser is focused. For example, a case ID or account ID. This method is onlyavailable in API version 25.0 or later.Syntaxsforce.console.getFocusedSubtabId((optional)callback:Function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to get the ID of the focused subtabfunction testGetFocusedSubtabId() {sforce.console.getFocusedSubtabId(showTabId);}var showTabId = function showTabId(result) {// Display the tab IDalert ('Tab ID: ' + result.id);};ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NameidsuccessTypestringbooleanDescriptionThe ID of the subtab on which the browser is focused. If no subtab is open,the ID is null.true if returning the ID of the focused subtab was successful; false ifreturning the ID of the focused subtab wasn't successful.getFocusedSubtabObjectId()UsageReturns the object ID of the subtab on which the browser is focused. For example, a case ID or account ID. This method isonly available in API version 24.0 or later.26


Methods for Primary Tabs and SubtabsgetPageInfo()Syntaxsforce.console.getFocusedSubtabObjectId((optional)callback:Function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to get the object ID of the focused subtabfunction testGetFocusedSubtabObjectId() {sforce.console.getFocusedSubtabObjectId(showObjectId);}var showObjectId = function showObjectId(result) {// Display the object IDalert ('Object ID: ' + result.id);};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NameidsuccessTypestringbooleanDescriptionThe object ID of the subtab on which the browser is focused. If no subtab isopen, the ID is null.true if returning the object ID of the focused subtab was successful; falseif returning the object ID of the focused subtab wasn't successful.getPageInfo()UsageReturns page information for the specified tab after its content has loaded. If the tab ID is null, it returns page informationfor the enclosing primary tab or subtab. Note that to get the page information from a custom console <strong>com</strong>ponent, a tabIdmust be passed as the first parameter to this method.This method is only available in API version 26.0 or later.Syntaxsforce.console.getPageInfo(tabId:String, (optional)callback:Function)27


Methods for Primary Tabs and SubtabsgetPrimaryTabIds()ArgumentsNametabIdcallbackTypestringfunctionDescriptionID of the tab from which page information is returned.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to get page informationfunction testGetPageInfo() {//Get the page information of 'scc-pt-1'//This value is for example purposes onlyvar tabId = 'scc-pt-1';sforce.console.getPageInfo(tabId , showPageInfo);}var showPageInfo = function showPageInfo(result) {alert('Page Info: ' + result.pageInfo);};ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NamepageInfoTypestringDescriptionThe URL, and if applicable, the object ID, object name, and object type of the page. The datais returned in JSON format. For example:{"url":"http://na.salesforce.<strong>com</strong>/001x0000003DGQR","objectId":"001x0000003DGQR","objectName":"Acme","object":"Account"callbackfunctionJavaScript method called upon <strong>com</strong>pletion of the method.getPrimaryTabIds()UsageReturns all of the IDs of open primary tabs. This method is only available in API version 26.0 or later.Syntaxsforce.console.getPrimaryTabIds((optional) callback:Function)28


Methods for Primary Tabs and SubtabsgetSubtabIds()ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to get the primary tab IDsfunction testGetPrimaryTabIds() {sforce.console.getPrimaryTabIds(showTabId);}var showTabId = function showTabId(result) {//Display the primary tab IDsalert('Primary Tab IDs: ' + result.ids);};ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NameidssuccessTypestringbooleanDescriptionAn array of open primary tab IDs , in order of appearance.true if returning the IDs of open primary tabs was successful; false ifreturning the IDs of open primary tabs wasn't successful.getSubtabIds()UsageReturns all of the IDs of the subtabs on the primary tab specified by a primary tab ID. If the primary tab ID is null, it returnsthe IDs of the subtabs on the current primary tab. This method can only be called from a custom console <strong>com</strong>ponent or adetail page overwritten by a Visualforce page. This method is only available in API version 26.0 or later.Syntaxsforce.console.getSubtabIds( (optional) primaryTabId:String, (optional) callback:Function)ArgumentsNameprimaryTabIdcallbackTypestringfunctionDescriptionID of the primary tab from which the subtab IDs are returned.JavaScript method called upon <strong>com</strong>pletion of the method.29


Methods for Primary Tabs and SubtabsgetTabLink()Sample Code–VisualforceClick here to get the subtab IDsfunction testGetSubtabIds() {//Get the subtabs of the primary tab 'scc-pt-0'//This value is for example purposes onlyvar primaryTabId = 'scc-pt-0';sforce.console.getSubtabIds(primaryTabId , showTabId);}var showTabId = function showTabId(result) {//Display the subtab IDsalert('Subtab IDs: ' + result.ids);};ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NameidssuccessTypestringbooleanDescriptionAn array of open subtab IDs.true if firing the event was successful; false if firing the event wasn'tsuccessful.getTabLink()UsageRetrieves the URL to a tab, or group of related tabs, from the <strong>Salesforce</strong> console. This method is only available in API version28.0 or later.Syntaxsforce.console.getTabLink(level:String, (optional)tabId:String, (optional)callback:Function)ArgumentsNamelevelTypestringDescriptionLevel that matches one of the Link to Share options in the <strong>Salesforce</strong> consoleuser interface. The options are:• All primary tabs and subtabs —sforce.console.TabLink.PARENT_AND_CHILDREN.• Only the specified tab — sforce.console.TabLink.TAB_ONLY• A standard <strong>Salesforce</strong> URL —sforce.console.TabLink.SALESFORCE_URL30


Methods for Primary Tabs and SubtabsisIn<strong>Console</strong>()NametabIdcallbackTypestringfunctionDescriptionFor more information, see “Work with Tabs in a <strong>Salesforce</strong> <strong>Console</strong>” in theonline help.Optional tab ID of the tab from which you’re retrieving the URL. If you donot pass a tab ID, the URL to the current tab is returned.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to get tab linkvar getEnclosingPrimaryTabId = function getEnclosingPrimaryTabId() {sforce.console.getEnclosingPrimaryTabId(getTabLink);}var getTabLink = function getTabLink(result) {sforce.console.getTabLink(sforce.console.TabLink.PARENT_AND_CHILDREN, result.id,showTabLink);}var showTabLink = function showTabLink(result) {var link = result.tabLink;};ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NametabLinksuccesscallbackTypestringbooleanfunctionDescriptionThe retrieved URL.true if the link was retrieved successfully, false if retrieving was unsuccessful.JavaScript method called upon <strong>com</strong>pletion of the method.isIn<strong>Console</strong>()UsageDetermines if the page is in the <strong>Salesforce</strong> console. This method is only available in API version 22.0 or later.Syntaxsforce.console.isIn<strong>Console</strong>()ArgumentsNone31


Methods for Primary Tabs and SubtabsonEnclosingTabRefresh()Sample Code–VisualforceClick here to check if the page is in the <strong>Service</strong> <strong>Cloud</strong> consolefunction testIsIn<strong>Console</strong>() {if (sforce.console.isIn<strong>Console</strong>()) {alert('in console');} else {alert('not in console');}}Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseReturns true if the page is in the <strong>Salesforce</strong> console; false if the page is not in the <strong>Salesforce</strong> console.onEnclosingTabRefresh()UsageRegisters a function to call when the enclosing tab refreshes. This method is only available in API version 24.0 or later.Syntaxsforce.console.onEnclosingTabRefresh(eventHandler:Function)ArgumentsNameeventHandlerTypefunctionDescriptionJavaScript method called when the enclosing tab refreshes.Sample Code–Visualforcevar eventHandler = function eventHandler(result) {alert('Enclosing tab has refreshed:' + result.id+ 'and the object Id is:' + result.objectId);};sforce.console.onEnclosingTabRefresh(eventHandler);32


Methods for Primary Tabs and SubtabsonFocusedSubtab()Event Handler ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NameidobjectIdTypestringstringDescriptionThe ID of the refreshed tab.The object ID of the refreshed tab or null if no object exists.onFocusedSubtab()UsageRegisters a function to call when the focus of the browser changes to a different subtab. This method is only available in APIversion 24.0 or later.Syntaxsforce.console.onFocusedSubtab(eventHandler:Function)ArgumentsNameeventHandlerTypefunctionDescriptionJavaScript method called when the focus of the browser changes to a differentsubtab.Sample Code–Visualforcevar eventHandler = function (result) {alert('Focus changed to a different subtab. The subtab Id is:'+ result.id + 'and the object Id is:' + result.objectId);};sforce.console.onFocusedSubtab(eventHandler);Event Handler ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NameidobjectIdTypestringstringDescriptionThe ID of the subtab on which the browser is focused.The object ID of the subtab on which the browser is focused or null if no objectexists.33


Methods for Primary Tabs and SubtabsonTabSave()onTabSave()UsageRegisters and calls a callback method when a user clicks Save in a subtab’s Unsaved Changes dialog box. When using thismethod, you must call setTabUnsavedChanges() in the callback method. This notifies the console that the custom saveoperation <strong>com</strong>pleted. In the call to setTabUnsavedChanges(), pass the first parameter as false to indicate a successfulsave 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 twooptions when closing a tab with unsaved changes: Continue or Cancel. When a save handler is registered, the user is presentedwith three options when closing the tab: Save, Don’t Save, or Cancel. In this scenario, the callback method registered is calledwhen the user chooses Save.Important: When using onTabSave() with setTabUnsavedChanges():• Note that calling sforce.console.setTabUnsavedChanges(false,...) closes the specified tab. Were<strong>com</strong>mend placing the call to sforce.console.setTabUnsavedChanges() at the end of the callbackmethod, as any subsequent save logic might not execute.• Not calling sforce.console.setTabUnsavedChanges() will have a severe affect on the user interface. Forexample, closing a primary tab with a subtab for which sforce.console.setTabUnsavedChanges() hasnot been called prevents a Saving... modal dialog box from closing.• Any callback passed to sforce.console.setTabUnsavedChanges() will not execute if the specified tabsaves successfully and closes.Note: Calling onTabSave() from a custom console <strong>com</strong>ponent prevents that <strong>com</strong>ponent from refreshing whensaving the tab. For more information on custom console <strong>com</strong>ponents, see “Custom <strong>Console</strong> Components Overview”in the <strong>Salesforce</strong> online help.Syntaxsforce.console.onTabSave(callback:Function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called to handle the save operation.Sample Code–VisualforceClick here to register save handlerfunction testOnTabSave() {sforce.console.onTabSave(handleSave);}var handleSave = function handleSave(result) {alert('save handler called from tab with id ' + result.id +' and objectId ' + result.objectId);//Perform save logic here34


Methods for Primary Tabs and Subtabsopen<strong>Console</strong>Url()//Mark tab as 'clean'sforce.console.setTabUnsavedChanges(false, undefined, result.id);};ResponseNameidobjectIdTypestringstringDescriptionID of the tab being saved.Object ID of the tab being saved, if applicable; null otherwise.open<strong>Console</strong>Url()UsageOpens a URL created by the generate<strong>Console</strong>Url() method (a URL to a tab, or group of related tabs, in the <strong>Salesforce</strong>console). This method is only available in API version 28.0 or later.Syntaxsforce.console.open<strong>Console</strong>Url(id:String, consoleUrl:URL, active:Boolean,(optional)tabLabels:String, (optional)tabNames:String, (optional)callback:Function)ArgumentsNameidconsoleUrlactivetabLabelstabNamescallbackTypestringstringbooleanstringstringfunctionDescriptionID of the console tab to override. If the ID corresponds to an existing primarytab, then the existing primary tab is redirected to the given URL because theconsole prevents duplicate tabs. Use null to create a new primary tab.<strong>Console</strong> URL that represents the array of URLs passed into <strong>Salesforce</strong>.If true, the opened primary tab displays immediately. If false, the openedprimary tab displays in the background and the current tab maintains focus.Optional array of labels of the opened primary tab or subtabs. The order inwhich the tabs appear in the console URL should match the order of the labelsthat appear in the array. If you do not want to set the labels of tabs, use anempty string ('').Optional array of names of the opened primary and subtabs. The order inwhich the tabs appear in the console URL should match the order of the namesthat appear in the array. If you do not want to set the names of tabs, use anempty string ('').JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to open a console URL35


Methods for Primary Tabs and SubtabsopenPrimaryTab()var generate<strong>Console</strong>Url = function testGenerate<strong>Console</strong>URL {sforce.console.generate<strong>Console</strong>Url([/apex/pagename, /entityId, www.externalUrl.<strong>com</strong>,Standard <strong>Salesforce</strong> Url/entityId], show<strong>Console</strong>Url);}var open<strong>Console</strong>Url = function show<strong>Console</strong>Url(result) {sforce.console.open<strong>Console</strong>Url(null, result.consoleUrl, true, ['Apex', '','<strong>Salesforce</strong>', ''], ['', '', 'externalUrl', ''])}Note: This example shows that if you want to set a label or name, you must set the other values to empty string (‘’).ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if the console URL was opened successfully, false otherwise.openPrimaryTab()UsageOpens a new primary tab to display the content of the specified URL, which can be relative or absolute. You can also overridean existing tab. This method is only available in API version 20.0 or later.• If the ID corresponds to an existing primary tab, the existing tab is redirected to the given URL because the <strong>Salesforce</strong>console prevents duplicate tabs.• If the URL is to a <strong>Salesforce</strong> object, that object displays as specified in the <strong>Salesforce</strong> console app settings. For example,if cases are set to open as a subtab of their parent accounts, and openPrimaryTab() is called on a case, the case opensas subtab on its parent account's primary tab.If there's an error opening the tab, the error code is reported in the JavaScript console.Syntaxsforce.console.openPrimaryTab(id:String, url:URL, active:Boolean, (optional)tabLabel:String,(optional)callback:Function, (optional)name)ArgumentsNameidTypestringDescriptionID of the primary tab to override.Use null to create a new primary tab.If the ID corresponds to an existing primary tab, the existing tab is redirectedto the given URL because the <strong>Salesforce</strong> console prevents duplicate tabs.36


Methods for Primary Tabs and SubtabsopenPrimaryTab()NameurlactivetabLabelcallbacknameTypeURLbooleanstringfunctionstringDescriptionURL of the opened primary tab.If the URL is to a <strong>Salesforce</strong> object, that object displays as specified in the<strong>Salesforce</strong> console app settings. For example, if cases are set to open as a subtabof their parent accounts, and openPrimaryTab() is called on a case, the caseopens as subtab on its parent account's primary tab.Note that users can open an external URL if it has been added to the console’swhitelist. For more information, see “Whitelist Domains for a <strong>Salesforce</strong><strong>Console</strong>” in the online help.If true, the opened primary tab displays immediately. If false, the openedprimary tab displays in the background and the current tab maintains focus.Optional label of the opened primary tab. If a label isn't specified, ExternalPage displays.Add labels as text; HTML isn't supported.JavaScript method called upon <strong>com</strong>pletion of the method.Optional name of the opened primary tab.This argument is only available in API version 22.0 and later.Sample Code–VisualforceClick here to open a new primary tabfunction testOpenPrimaryTab() {//Open a new primary tab with the salesforce.<strong>com</strong> home page in itsforce.console.openPrimaryTab(null, 'http://www.salesforce.<strong>com</strong>', false,'salesforce', openSuccess, 'salesforceTab');}var openSuccess = function openSuccess(result) {//Report whether opening the new tab was successfulif (result.success == true) {alert('Primary tab successfully opened');} else {alert('Primary tab cannot be opened');}};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:37


Methods for Primary Tabs and SubtabsopenSubtab()NamesuccessidTypebooleanstringDescriptiontrue if the tab successfully opened; false if the tab didn't open.ID of the primary tab. IDs are only valid during a user session; IDs be<strong>com</strong>einvalid when a user leaves the <strong>Salesforce</strong> console.openSubtab()UsageOpens a new subtab (within a primary tab) that displays the content of a specified URL, which can be relative or absolute.You can also override an existing subtab. Use to open a new subtab on a primary tab via the primary tab's ID. This method isonly available in API version 20.0 or later.If there's an error opening the tab, the error code is reported in the JavaScript console.Syntaxsforce.console.openSubtab(primaryTabId:String, url:URL, active:Boolean, tabLabel:String,id:String, (optional)callback:Function, (optional)name:String)ArgumentsNameprimaryTabIdurlactivetabLabelidcallbacknameTypestringURLbooleanstringstringfunctionstringDescriptionID of the primary tab in which the subtab opened.URL of the opened subtab.If the URL is to a <strong>Salesforce</strong> object, that object displays as specified in the<strong>Salesforce</strong> console app settings. For example, if cases are set to open as a primarytab, and openSubtab() is called on a case, the case opens as a primary tab.Note that users can open an external URL if it has been added to the console’swhitelist. For more information, see “Whitelist Domains for a <strong>Salesforce</strong><strong>Console</strong>” in the online help.If true, the opened subtab displays immediately. If false, the opened subtabdisplays in the background and the current tab maintains focus.Optional label of the opened subtab. If a label isn't specified, ExternalPage displays.Add labels as text; HTML isn't supported.ID of the subtab to override.Use null to create a new subtab.JavaScript method called upon <strong>com</strong>pletion of the method.Optional name of the opened subtab.This argument is only available in API version 22.0 and later.38


Methods for Primary Tabs and SubtabsopenSubtabByPrimaryTabName()Sample Code–VisualforceClick here to open a new subtabfunction testOpenSubtab() {//First find the ID of the primary tab to put the new subtab insforce.console.getEnclosingPrimaryTabId(openSubtab);}var openSubtab = function openSubtab(result) {//Now that we have the primary tab ID, we can open a new subtab in itvar primaryTabId = result.id;sforce.console.openSubtab(primaryTabId , 'http://www.salesforce.<strong>com</strong>', false,'salesforce', null, openSuccess, 'salesforceSubtab');};var openSuccess = function openSuccess(result) {//Report whether we succeeded in opening the subtabif (result.success == true) {alert('subtab successfully opened');} else {alert('subtab cannot be opened');}};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NamesuccessidTypebooleanstringDescriptiontrue if the subtab successfully opened; false if the subtab didn't open.ID of the subtab. IDs are only valid during a user session; IDs be<strong>com</strong>e invalidwhen the user leaves the <strong>Salesforce</strong> console.openSubtabByPrimaryTabName()UsageOpens a new subtab (within a primary tab) that displays the content of a specified URL, which can be relative or absolute.You can also override an existing subtab. Use to open a new subtab on a primary tab via the primary tab's name. This methodis only available in API version 22.0 or later.If there's an error opening the tab, the error code is reported in the JavaScript console.39


Methods for Primary Tabs and SubtabsopenSubtabByPrimaryTabName()Syntaxsforce.console.openSubtabByPrimaryTabName(primaryTabName:String, url:URL, active:Boolean,tabLabel:String, id:String, (optional)callback:Function, (optional)name:String)ArgumentsNameprimaryTabNameurlactivetabLabelidcallbacknameTypestringURLbooleanstringstringfunctionstringDescriptionName of the primary tab in which the subtab opened.URL of the opened subtab.If the URL is to a <strong>Salesforce</strong> object, that object displays as specified in the<strong>Salesforce</strong> console app settings. For example, if cases are set to open as a primarytab, and openSubtab() is called on a case, the case opens as a primary tab.Note that users can open an external URL if it has been added to the console’swhitelist. For more information, see “Whitelist Domains for a <strong>Salesforce</strong><strong>Console</strong>” in the online help.If true, the opened subtab displays immediately. If false, the opened subtabdisplays in the background and the current tab maintains focus.Optional label of the opened subtab. If a label isn't specified, ExternalPage displays.Add labels as text; HTML isn't supported.ID of the subtab to override.Use null to create a new subtab.JavaScript method called upon <strong>com</strong>pletion of the method.Optional name of the opened subtab.This argument is only available in API version 22.0 and later.Sample Code–VisualforceClick here to open a new subtab by primary tab namefunction testOpenSubtabByPrimaryTabName() {//First open a primary tab by namesforce.console.openPrimaryTab(null, 'http://www.yahoo.<strong>com</strong>', true, 'Yahoo',openSubtab, 'yahoo');}var openSubtab = function openSubtab(result) {//Open the subtab by the name specified in functiontestOpenSubtabByPrimaryTabName()sforce.console.openSubtabByPrimaryTabName('yahoo', 'http://www.salesforce.<strong>com</strong>',true,'salesforce', null, openSuccess);};var openSuccess = function openSuccess(result) {//Report whether we succeeded in opening the subtab40


Methods for Primary Tabs and SubtabsrefreshPrimaryTabById()if (result.success == true) {alert('subtab successfully opened');} else {alert('subtab cannot be opened');}};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NamesuccessidTypebooleanstringDescriptiontrue if the subtab successfully opened; false if the subtab didn't open.ID of the subtab. IDs are only valid during a user session; IDs be<strong>com</strong>e invalidwhen the user leaves the <strong>Salesforce</strong> console.refreshPrimaryTabById()UsageRefreshes a primary tab specified by ID, including its subtabs. This method can't refresh subtabs with URLs to external pagesor Visualforce pages. This method is only available in API version 22.0 or later.Note that this method doesn't refresh sidebars or custom console <strong>com</strong>ponents. For more information, see Custom <strong>Console</strong>Components Overview in the <strong>Salesforce</strong> online help.Syntaxsforce.console.refreshPrimaryTabById(id:String, active:Boolean, (optional)callback:Function)ArgumentsNameidactivecallbackTypestringbooleanfunctionDescriptionID of the primary tab to refresh.If true, the refreshed primary tab displays immediately. If false, the refreshedprimary tab displays in the background.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to refresh a primary tab by id41


Methods for Primary Tabs and SubtabsrefreshPrimaryTabByName()function testRefreshPrimaryTabById() {//Get the value for 'scc-pt-0' from the openPrimaryTab method//This value is for example purposes onlyvar primaryTabId = 'scc-pt-0';sforce.console.refreshPrimaryTabById(primaryTabId, true, refreshSuccess);}var refreshSuccess = function refreshSuccess(result) {//Report whether refreshing the primary tab was successfulif (result.success == true) {alert('Primary tab refreshed successfully');} else {alert('Primary did not refresh');}};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if the primary tab refreshed successfully; false if the primary tab didn'trefresh.refreshPrimaryTabByName()UsageRefreshes a primary tab specified by name, including its subtabs. This method can't refresh subtabs with URLs to externalpages or Visualforce pages. This method is only available in API version 22.0 or later.Note that this method doesn't refresh sidebars or custom console <strong>com</strong>ponents. For more information, see Custom <strong>Console</strong>Components Overview in the <strong>Salesforce</strong> online help.Syntaxsforce.console.refreshPrimaryTabByName(name:String, active:Boolean,(optional)callback:Function)ArgumentsNamenameTypestringDescriptionName of the primary tab to refresh.42


Methods for Primary Tabs and SubtabsrefreshSubtabById()NameactivecallbackTypebooleanfunctionDescriptionIf true, the refreshed primary tab displays immediately. If false, the refreshedprimary tab displays in the background.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to refresh a primary tab by namefunction testRefreshPrimaryTabByName() {//Set the name of the tab by using the openPrimaryTab method//This value is for example purposes onlyvar primaryTabName = 'myPrimaryTab';sforce.console.refreshPrimaryTabByName(primaryTabName, true, refreshSuccess);}var refreshSuccess = function refreshSuccess(result) {//Report whether refreshing the primary tab was successfulif (result.success == true) {alert('Primary tab refreshed successfully');} else {alert('Primary tab did not refresh');}};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if the primary tab refreshed successfully; false if the primary tab didn'trefresh.refreshSubtabById()UsageRefreshes a subtab with the last known URL with a specified ID. This method can't refresh a subtab If the last known URLis an external page or a Visualforce page. This method is only available in API version 22.0 or later.Note that this method doesn't refresh sidebars or custom console <strong>com</strong>ponents. For more information, see Custom <strong>Console</strong>Components Overview in the <strong>Salesforce</strong> online help.43


Methods for Primary Tabs and SubtabsrefreshSubtabById()Syntaxsforce.console.refreshSubtabById(id:String, active:Boolean, (optional)callback:Function)ArgumentsNameidactivecallbackTypestringbooleanfunctionDescriptionID of the subtab to refresh.If true, the refreshed subtab displays immediately. If false, the refreshedsubtab displays in the background.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to refresh a subtab by idfunction testRefreshSubtabById() {//Set the name of the tab by using the openSubtab method//This value is for example purposes onlyvar subtabId = 'scc-st-0';sforce.console.refreshSubtabById(subtabId, true, refreshSuccess);}var refreshSuccess = function refreshSuccess(result) {//Report whether refreshing the subtab was successfulif (result.success == true) {alert('Subtab refreshed successfully');} else {alert('Subtab did not refresh');}};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if the subtab refreshed successfully; false if the subtab didn't refresh.44


Methods for Primary Tabs and SubtabsrefreshSubtabByNameAndPrimaryTabId()refreshSubtabByNameAndPrimaryTabId()UsageRefreshes a subtab with the last known URL with the specified name and primary tab ID. This method can't refresh a subtabIf the last known URL is an external page or a Visualforce page. This method is only available in API version 22.0 or later.Note that this method doesn't refresh sidebars or custom console <strong>com</strong>ponents. For more information, see Custom <strong>Console</strong>Components Overview in the <strong>Salesforce</strong> online help.Syntaxsforce.console.refreshSubtabByNameAndPrimaryTabId(name:String, primaryTabId:String,active:Boolean, (optional)callback:Function)ArgumentsNamenameprimaryTabIdactivecallbackTypestringstringbooleanfunctionDescriptionName of the subtab to refresh.ID of the primary tab in which the subtab opened.If true, the refreshed subtab displays immediately. If false, the refreshedsubtab displays in the background.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to refresh a subtab by name and primary tab IDfunction testRefreshSubtabByNameAndPrimaryTabId() {//Get the value for 'mySubtab' and 'scc-pt-0' from the openSubtab method//These values are for example purposes onlyvar subtabName = 'mySubtab';var primaryTabId = 'scc-pt-0';sforce.console.refreshSubtabByNameAndPrimaryTabId(subtabName, primaryTabId,true, refreshSuccess);}var refreshSuccess = function refreshSuccess(result) {//Report whether refreshing the subtab was successfulif (result.success == true) {alert('Subtab refreshed successfully');} else {alert('Subtab did not refresh');}};45


Methods for Primary Tabs and SubtabsrefreshSubtabByNameAndPrimaryTabName()Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if the subtab refreshed successfully; false if the subtab didn't refresh.refreshSubtabByNameAndPrimaryTabName()UsageRefreshes a subtab with the last known URL with the specified name and primary tab name. This method can't refresh asubtab If the last known URL is an external page or a Visualforce page. This method is only available in API version 22.0 orlater.Note that this method doesn't refresh sidebars or custom console <strong>com</strong>ponents. For more information, see Custom <strong>Console</strong>Components Overview in the <strong>Salesforce</strong> online help.Syntaxsforce.console.refreshSubtabByNameAndPrimaryTabName(name:String, primaryTabName:String,active:Boolean, (optional)callback:Function)ArgumentsNamenameprimaryTabNameactivecallbackTypestringstringbooleanfunctionDescriptionName of the subtab to refresh.Name of the primary tab in which the subtab opened.If true, the refreshed subtab displays immediately. If false, the refreshedsubtab displays in the background.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to refresh a subtab by name and primary tab namefunction testRefreshSubtabByNameAndPrimaryTabName() {//Get the value for 'mySubtab' and 'myPrimaryTab' from the openSubtab method//These values are for example purposes onlyvar subtabName = 'mySubtab';var primaryTabName = 'myPrimaryTab';sforce.console.refreshSubtabByNameAndPrimaryTabName(subtabName, primaryTabName,46


Methods for Primary Tabs and SubtabsresetSessionTimeOut()true, refreshSuccess);}var refreshSuccess = function refreshSuccess(result) {//Report whether refreshing the subtab was successfulif (result.success == true) {alert('Subtab successfully refreshed');} else {alert('Subtab did not refresh');}};Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if the subtab refreshed successfully; false if the subtab didn't refresh.resetSessionTimeOut()UsageResets a session timeout on a Visualforce page so that users can continue working without being logged out. For moreinformation, see “Setting Session Security” in the <strong>Salesforce</strong> Help. This method is only available in API version 24.0 or later.Syntaxsforce.console.resetSessionTimeOut()ArgumentsNoneSample Code–VisualforceClick here to reset session timeoutfunction testResetSessionTimeOut() {sforce.console.resetSessionTimeOut();};47


Methods for Primary Tabs and SubtabssetTabUnsavedChanges()Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseNonesetTabUnsavedChanges()UsageSets the unsaved changes icon ( ) on subtabs to indicate unsaved data. This method is only available in API version 23.0 orlater.Syntaxsforce.console.setTabUnsavedChanges(unsaved:Boolean, callback:Function,(optional)subtabId:String)ArgumentsNameunsavedcallbacksubtabIdTypebooleanfunctionstringDescriptionIf true, the tab is marked as having unsaved changes.JavaScript method called upon <strong>com</strong>pletion of the method.The ID of the subtab that is marked as having unsaved changes.This argument is only available in API version 25.0 or later.Sample Code API Version 23.0 or Later–VisualforceClick here to indicate this tab has unsaved changesfunction testSetTabUnsavedChanges() {sforce.console.setTabUnsavedChanges(true, displayResult);};function displayResult(result) {if (result.success) {alert('Tab status has been successfully updated');} else {alert('Tab status couldn’t be updated');}}Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.48


Methods for Primary Tabs and SubtabssetTabIcon()ResponseThis method returns its response in an object in a callback method. The response object contains the following field:NamesuccessTypebooleanDescriptiontrue if update was successful; false if update wasn't successful.Sample Code API Version 25.0 or Later–VisualforceClick here to indicate this tab has unsaved changesfunction testSetTabUnsavedChanges() {sforce.console.getFocusedSubtabId(setTabDirty);};function setTabDirty(result) {sforce.console.setTabUnsavedChanges(true, displayResult, result.id);};function displayResult(result) {if (result.success) {alert('Tab status has been successfully updated');} else {alert('Tab status couldn’t be updated');}};Note: This example is only set to run if the Visualforce page is inside an application-level custom <strong>com</strong>ponent. Formore information, see Methods for Application-Level Custom <strong>Console</strong> Components on page 62.ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if returning the focused subtab ID was successful; false if if returningthe focused subtab ID wasn't successful.setTabIcon()UsageSets an icon on the specified tab. If a tab is not specified, the icon is set on the enclosing tab. Use this method to customize atab’s icon. This method is only available in API version 28.0 or later.Syntaxsforce.console.setTabIcon(iconUrl:String, tabID:String, (optional)callback:Function)49


Methods for Primary Tabs and SubtabssetTabIcon()ArgumentsNameiconUrltabIdcallbackTypestringstringfunctionDescriptionA URL pointing to an image, which is used as the tab’s icon. If null orundefined, the tab’s default icon is used.The ID of the tab on which to set the icon. If null or undefined, the enclosingtab’s ID is used.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to change the enclosing tab’s icon Click here to reset the enclosing tab’s iconfunction checkResult(result) {if (result.success) {alert('Tab icon set successfully!');} else {alert('Tab icon cannot be set!');}}function testSetTabIcon() {sforce.console.setTabIcon('http://host/path/to/your/icon.png', null, checkResult);}function testResetTabIcon() {sforce.console.setTabIcon(null, null, checkResult);}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if setting the tab’s icon was successful, false if setting the tab’s iconwasn’t successful.Note: If this method is called without passing in a tab ID, the tab in which the Visualforce page is enclosed is used.If there isn’t an enclosing tab, the error message Cannot get a workspace or view tab from thegiven ID displays in the browser’s developer console.50


Methods for Primary Tabs and SubtabssetTabTextStyle()ArgumentsNamestyletabIdcallbackTypestringstringfunctionDescriptionA CSS specification string used to style the tab. If null or undefined, the tab’sdefault style is used.The ID of the tab on which to set the style. If null or undefined, the enclosingtab’s ID is used.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to change the enclosing tab’s background color to red Click here to reset the enclosing tab’s stylefunction checkResult(result) {if (result.success) {alert('Tab style set successfully!');} else {alert('Tab style cannot be set!');}}function testSetTabStyle() {sforce.console.setTabStyle('background:red;', null, checkResult);}function testResetTabStyle() {sforce.console.setTabStyle(null, null, checkResult);}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if setting the tab’s style was successful, false if setting the tab’s stylewasn’t successful.Note: If this method is called without passing in a tab ID, the tab in which the Visualforce page is enclosed is used.If there isn’t an enclosing tab, the error message Cannot get a workspace or view tab from thegiven ID displays in the browser’s developer console.setTabTextStyle()UsageSets a cascading style sheet (CSS) on a specified tab’s text. If a tab is not specified, the CSS is set on the enclosing tab’s text.Use this method to customize a tab’s text style. This method is only available in API version 28.0 or later.52


Methods for Primary Tabs and SubtabssetTabTextStyle()Syntaxsforce.console. setTabTextStyle(style:String, tabID:String, (optional)callback:Function))ArgumentsNamestyletabIdcallbackTypestringstringfunctionDescriptionA CSS specification string used to set a tab’s text style. If null or undefined,the tab’s default text style is used.The ID of the tab on which to set the text style. If null or undefined, theenclosing tab’s ID is used.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to change the enclosing tab’s text style Click here to reset the enclosing tab’s text stylefunction checkResult(result) {if (result.success) {alert('Tab text style set successfully!');} else {alert('Tab text style cannot be set!');}}function testSetTabTextStyle() {sforce.console.setTabTextStyle('color:blue;font-style:italic;', null,checkResult);}function testResetTabTextStyle() {sforce.console.setTabTextStyle(null, null, checkResult);}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if setting the tab’s text style was successful, false if setting the tab’stext style wasn’t successful.Note: If this method is called without passing in a tab ID, the tab in which the Visualforce page is enclosed is used.If there isn’t an enclosing tab, the error message Cannot get a workspace or view tab from thegiven ID displays in the browser’s developer console.53


Methods for Primary Tabs and SubtabssetTabTitle()setTabTitle()UsageSets the title of a primary tab or subtab. This method is only available in API version 20.0 or later.Syntaxsforce.console.setTabTitle(tabTitle:String, (optional)tabID:String)ArgumentsNametabTitletabIdTypestringstringDescriptionTitle of a primary tab or subtab.The ID of the tab in which to set the title.This argument is only available in API version 25.0 or later.Sample Code–Visualforce API Version 20.0 or LaterClick here to change this tab's titlefunction testSetTabTitle() {//Set the current tab's titlesforce.console.setTabTitle('My New Title');}Note: This example is set to run by clicking a custom link on a case. For more information, see “Defining CustomButtons and Links” in the <strong>Salesforce</strong> online help.ResponseNoneSample Code–Visualforce API Version 25.0 or LaterClick here to change the title of the focused primary tabsforce.console.getFocusedPrimaryTabId(function(result){sforce.console.setTabTitle('My New Title', result.id);});54


Methods for Primary Tabs and SubtabssetTabTitle()Note: This example is only set to run if the Visualforce page is inside an application-level custom <strong>com</strong>ponent. Formore information, see Methods for Application-Level Custom <strong>Console</strong> Components on page 62.ResponseNone55


Chapter 4Methods for Computer-Telephony <strong>Integration</strong> (CTI)<strong>Salesforce</strong> CRM Call Center seamlessly integrates <strong>Salesforce</strong> with third-party <strong>com</strong>puter-telephony integration (CTI) systems.After a lightweight CTI adapter program has been installed on a <strong>Salesforce</strong> user's machine, the user can use the features of aCTI system through the <strong>Salesforce</strong> SoftPhone, a customizable call-control tool that appears in the footer of the <strong>Salesforce</strong>console or in sidebar of every <strong>Salesforce</strong> page.For more information on CTI, see “Call Center Overview” in the <strong>Salesforce</strong> online help.You can use the following methods for a CTI system with the <strong>Salesforce</strong> console:MethodgetCallAttachedData()getCallObjectIds()onCallBegin()onCallEnd()sendCTIMessage()DescriptionReturns the attached data of a call represented by the call objectID or null if there isn’t an active call. The data is returned in JSONformat. This method is for <strong>com</strong>puter-telephony integration (CTI);it’s only available in API version 24.0 or later.Returns any active call object IDs in the order in which they arrivedor null if there aren’t any active calls. This method is for<strong>com</strong>puter-telephony integration (CTI); it’s only available in APIversion 24.0 or later.Registers a function that is called when a call begins (<strong>com</strong>es in).This method is for <strong>com</strong>puter-telephony integration (CTI); it’s onlyavailable in API version 24.0 or later.Registers a function that is called when a call ends. This methodis for <strong>com</strong>puter-telephony integration (CTI); it’s only available inAPI version 24.0 or later.Sends a message to the CTI adapter. This method is for<strong>com</strong>puter-telephony integration (CTI); it’s only available in APIversion 24.0 or later.getCallAttachedData()UsageReturns the attached data of a call represented by the call object ID or null if there isn’t an active call. The data is returned inJSON format. This method is for <strong>com</strong>puter-telephony integration (CTI); it’s only available in API version 24.0 or later.56


Methods for Computer-Telephony <strong>Integration</strong> (CTI)getCallObjectIds()Syntaxsforce.console.cti.getCallAttachedData( callObjectId, (optional) callback:Function )ArgumentsNamecallObjectIdcallbackTypestringfunctionDescriptionThe call object ID of the call that retrieves the attached data.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–Visualforcevar callback2 = function (result) {alert('Call attached data is ' + result.data);};};/* Retrieving call ID of first call that came in and* calling getCallAttachedData() to retrieve call data.*/var callback1 = function (result) {if (result.ids && result.ids.length > 0) {sforce.console.cti.getCallAttachedData(result.ids[0], callback2);}}//Note that we are using the CTI submodule heresforce.console.cti.getCallObjectIds(callback1);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NamedatasuccesstypeTypestringbooleanstringDescriptionThe attached data of a call in JSON format.true if returning the attached data was successful; false if returning theattached data wasn’t successful.The type of call. Possible values are 'INTERNAL', 'INBOUND', and'OUTBOUND'.getCallObjectIds()UsageReturns any active call object IDs in the order in which they arrived or null if there aren’t any active calls. This method is for<strong>com</strong>puter-telephony integration (CTI); it’s only available in API version 24.0 or later.57


Methods for Computer-Telephony <strong>Integration</strong> (CTI)onCallBegin()Syntaxsforce.console.getCallObjectIds( (optional) callback:Function )ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–Visualforcevar callback = function (result) {alert('Active call object ids: ' + result.ids);};//Note that we are using the CTI submodule heresforce.console.cti.getCallObjectIds(callback);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NameidssuccessTypestringbooleanDescriptionThe call object IDs of active calls or null if no call is active.true if returning the active call object IDs was successful; false if returningthe active call object IDs wasn’t successful.onCallBegin()UsageRegisters a function that is called when a call begins (<strong>com</strong>es in). This method is for <strong>com</strong>puter-telephony integration (CTI);it’s only available in API version 24.0 or later.Syntaxsforce.console.onCallBegin( eventHandler:Function )ArgumentsNameeventHandlerTypefunctionDescriptionJavaScript method called when a call begins.58


Methods for Computer-Telephony <strong>Integration</strong> (CTI)onCallEnd()Sample Code–Visualforcevar callback = function (result) {alert('Call ' + result.id + 'Just came in!');};//Note that we are using the CTI submodule heresforce.console.cti.onCallBegin(callback);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NameidTypestringDescriptionThe call object ID of the call which has begun.onCallEnd()UsageRegisters a function that is called when a call ends. This method is for <strong>com</strong>puter-telephony integration (CTI); it’s only availablein API version 24.0 or later.Syntaxsforce.console.onCallEnd( eventHandler:Function )ArgumentsNameeventHandlerTypefunctionDescriptionJavaScript method called when a call ends.Sample Code–Visualforcevar callback = function (result) {var str = 'Call ' + result.id + ' ended! ';str += 'Call duration is ' + result.duration + '. ';str += 'Call disposition is ' + result.disposition;alert(str);};//Note that we are using the CTI submodule heresforce.console.cti.onCallEnd(callback);59


Methods for Computer-Telephony <strong>Integration</strong> (CTI)sendCTIMessage()ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NameiddurationdispositionTypestringstringstringDescriptionThe call object ID of the call which has ended.The duration of the call.The disposition of the call.sendCTIMessage()UsageSends a message to the CTI adapter. This method is for <strong>com</strong>puter-telephony integration (CTI); it’s only available in APIversion 24.0 or later.Syntaxsforce.console.sendCTIMessage( msg, (optional) callback:Function )ArgumentsNamemsgcallbackTypestringfunctionDescriptionMessage to send to the adapter.JavaScript method called when the message is sent.Sample Code–Visualforcevar callback = function (result) {if (result.success) {alert('CTI message was sent successfully!');} else {alert('CTI message was not sent successfully.');}};//Note that we are using the CTI submodule heresforce.console.cti.sendCTIMessage('/ANSWER?LINE_NUMBER=1', callback);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:60


Methods for Computer-Telephony <strong>Integration</strong> (CTI)sendCTIMessage()NamesuccessTypebooleanDescriptiontrue if sending the message was successful; false if sending the messagewasn’t successful.61


Chapter 5Methods for Application-Level Custom <strong>Console</strong> ComponentsCustom console <strong>com</strong>ponents let you customize, extend, or integrate the footer, sidebars, highlights panels, and interactionlogs of a <strong>Salesforce</strong> console using Visualforce, canvas apps, or lookup fields.Administrators can add custom console <strong>com</strong>ponents to either:• Page layouts to display content on specific pages• <strong>Salesforce</strong> console apps to display content across all pages and tabsFor more information, see “Custom <strong>Console</strong> Components Overview” in the <strong>Salesforce</strong> online help.You can use the following methods for custom console <strong>com</strong>ponents that display at the <strong>Salesforce</strong> console app-level:MethodaddToBrowserTitleQueue()blinkCustom<strong>Console</strong>ComponentButtonText()isCustom<strong>Console</strong>ComponentPoppedOut()isCustom<strong>Console</strong>ComponentWindowHidden()isInCustom<strong>Console</strong>Component()onCustom<strong>Console</strong>ComponentButtonClicked()onFocusedPrimaryTab()removeFromBrowserTitleQueue()DescriptionAdds a browser tab title to a list of titles, which rotates every threeseconds. This method is only available in API version 28.0 or later.Blinks a button’s text on an application-level custom console<strong>com</strong>ponent that’s on a page. This method is only available in APIversion 25.0 or later.Determines if a custom console <strong>com</strong>ponent is popped out from abrowser. To use this method, multi-monitor <strong>com</strong>ponents must beturned on. For more information, see “Turn on Multi-MonitorComponents for a <strong>Salesforce</strong> <strong>Console</strong>” in the online help. Thismethod is only available in API version 30.0 or later.Determines if the application-level custom console <strong>com</strong>ponentwindow is hidden.This method is only available in API version25.0 or later.Determines if the page is in an application-level custom console<strong>com</strong>ponent. This method is only available in API version 25.0 orlater.Registers a function to call when a button is clicked on anapplication-level custom console <strong>com</strong>ponent. This method is onlyavailable in API version 25.0 or later.Registers a function to call when the focus of the browser changesto a different primary tab. This method is only available in APIversion 25.0 or later.Removes a browser tab title from the list of titles, which rotatesevery three seconds. This method is only available in API version28.0 or later.62


Methods for Application-Level Custom <strong>Console</strong> ComponentsaddToBrowserTitleQueue()MethodscrollCustom<strong>Console</strong>ComponentButtonText()setCustom<strong>Console</strong>ComponentButtonIconUrl()setCustom<strong>Console</strong>ComponentButtonStyle()setCustom<strong>Console</strong>ComponentButtonText()setCustom<strong>Console</strong>ComponentPopoutable()setCustom<strong>Console</strong>ComponentWindowVisible()DescriptionScrolls a button’s text on an application-level custom console<strong>com</strong>ponent that’s on a page. This method is only available in APIversion 25.0 or later.Sets the button icon URL of an application-level custom console<strong>com</strong>ponent that’s on a page. This method is only available in APIversion 25.0 or later.Sets the style of a button used to launch an application-level customconsole <strong>com</strong>ponent that’s on a page. This method is only availablein API version 25.0 or later.Sets the text on a button used to launch an application-level customconsole <strong>com</strong>ponent that’s on a page. This method is only availablein API version 25.0 or later.Sets a custom console <strong>com</strong>ponent to be popped out or popped intoa browser. To use this method, multi-monitor <strong>com</strong>ponents mustbe turned on. For more information, see “Turn on Multi-MonitorComponents for a <strong>Salesforce</strong> <strong>Console</strong>” in the online help. Thismethod is only available in API version 30.0 or later.Sets the window visibility of an application-level custom console<strong>com</strong>ponent that’s on a page. This method is only available in APIversion 25.0 or later.addToBrowserTitleQueue()UsageAdds a browser tab title to a list of titles, which rotates every three seconds. This method is only available in API version 28.0or later.Syntaxsforce.console.addToBrowserTitleQueue( title:String, callback:Function )ArgumentsNametitlecallbackTypestringfunctionDescriptionBrowser tab title that is displayed.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to enqueue a browser title63


Methods for Application-Level Custom <strong>Console</strong> ComponentsblinkCustom<strong>Console</strong>ComponentButtonText()function testAddToBrowserTitleQueue() {var title = 'TestTitle';sforce.console.addToBrowserTitleQueue(title);}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NamesuccesscallbackTypebooleanfunctionDescriptionIf true, the title was successfully added to the browser title queue. If false,the title wasn’t added to the browser title queue.JavaScript method called upon <strong>com</strong>pletion of the method.blinkCustom<strong>Console</strong>ComponentButtonText()UsageBlinks a button’s text on an application-level custom console <strong>com</strong>ponent that’s on a page. This method is only available inAPI version 25.0 or later.Syntaxsforce.console.blinkCustom<strong>Console</strong>ComponentButtonText(alternateText:String, interval:number,(optional)callback:Function)ArgumentsNamealternateTextintervalcallbackTypestringnumberfunctionDescriptionThe alternate text to display when the button text blinks.Controls how often the text blinks in milliseconds.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to blink the button text on a custom console <strong>com</strong>ponentfunction testBlinkCustom<strong>Console</strong>ComponentButtonText() {//Blink the custom console <strong>com</strong>ponent button textsforce.console.blinkCustom<strong>Console</strong>ComponentButtonText('Hello World', 10,function(result){if (result.success) {alert('The text blinking starts!');} else {alert('Could not initiate the text blinking!');64


Methods for Application-Level Custom <strong>Console</strong> ComponentsisCustom<strong>Console</strong>ComponentPoppedOut()}});}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if blinking, the button text was successful; false if blinking the buttontext wasn't successful.isCustom<strong>Console</strong>ComponentPoppedOut()UsageDetermines if a custom console <strong>com</strong>ponent is popped out from a browser. To use this method, multi-monitor <strong>com</strong>ponentsmust be turned on. For more information, see “Turn on Multi-Monitor Components for a <strong>Salesforce</strong> <strong>Console</strong>” in the onlinehelp. This method is only available in API version 30.0 or later.Syntaxsforce.console.isCustom<strong>Console</strong>ComponentPoppedOut (callback:Function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceIs this <strong>com</strong>ponent popped out? function checkResult(result) {if (result.success) {alert('Is this <strong>com</strong>ponent popped out: ' + result.poppedOut);} else {alert('Error invoking this method. Check the browser developer console for moreinformation.');}}function checkPoppedOut() {sforce.console.isCustom<strong>Console</strong>ComponentPoppedOut(checkResult);}65


Methods for Application-Level Custom <strong>Console</strong> ComponentsisCustom<strong>Console</strong>ComponentWindowHidden()ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccesspoppedOutTypebooleanbooleanDescriptiontrue if returning the <strong>com</strong>ponent’s pop out status was successful; falseotherwise.true if the <strong>com</strong>ponent is popped out; false otherwise.isCustom<strong>Console</strong>ComponentWindowHidden()UsageDetermines if the application-level custom console <strong>com</strong>ponent window is hidden.This method is only available in API version25.0 or later.Note: If this method is called from a popped out <strong>com</strong>ponent in a <strong>Salesforce</strong> console where multi-montior <strong>com</strong>ponentsis turned on, nothing will happen. For more information, see “Turn on Multi-Monitor Components for a <strong>Salesforce</strong><strong>Console</strong>” in the online help.Syntaxsforce.console.isCustom<strong>Console</strong>ComponentWindowHidden((optional) callback:Function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to check if the custom console <strong>com</strong>ponent window is hiddenfunction testIsCustom<strong>Console</strong>ComponentWindowHidden() {sforce.console.isCustom<strong>Console</strong>ComponentWindowHidden(checkWindowVisibility);}var checkWindowVisibility = function checkWindowVisibility(result) {//Display the window visibilityif (result.success) {alert('Is window hidden: ' + result.hidden);} else {alert('Error!');}}66


Methods for Application-Level Custom <strong>Console</strong> ComponentsisInCustom<strong>Console</strong>Component()ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamehiddensuccessTypebooleanbooleanDescriptiontrue if the custom console <strong>com</strong>ponent window is hidden; false if the customconsole <strong>com</strong>ponent window is visible.true if returning the custom console <strong>com</strong>ponent window visibility wassuccessful; false if returning the custom console <strong>com</strong>ponent window visibilitywasn't successful.isInCustom<strong>Console</strong>Component()UsageDetermines if the page is in an application-level custom console <strong>com</strong>ponent. This method is only available in API version25.0 or later.Syntaxsforce.console.isInCustom<strong>Console</strong>Component((optional) callback:Function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to check if the page is in an app-level custom console <strong>com</strong>ponentfunction testIsInCustom<strong>Console</strong>Component() {sforce.console.isInCustom<strong>Console</strong>Component(checkInComponent);}Responsevar checkInComponent = function checkInComponent(result) {//Check if in <strong>com</strong>ponentalert('Is in custom console <strong>com</strong>ponent: ' + result.inCustom<strong>Console</strong>Component);};This method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:67


Methods for Application-Level Custom <strong>Console</strong> ComponentsonCustom<strong>Console</strong>ComponentButtonClicked()NameinCustom<strong>Console</strong>ComponentsuccessTypebooleanbooleanDescriptiontrue if the page is in a custom console <strong>com</strong>ponent; false if the page isn’t ina custom console <strong>com</strong>ponent.true if returning the page status was successful; false if returning the pagestatus wasn't successful.onCustom<strong>Console</strong>ComponentButtonClicked()UsageRegisters a function to call when a button is clicked on an application-level custom console <strong>com</strong>ponent. This method is onlyavailable in API version 25.0 or later.Syntaxsforce.console.onCustom<strong>Console</strong>ComponentButtonClicked(eventHandler:Function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called when a button is clicked on a custom console<strong>com</strong>ponent.Sample Code–Visualforcevar eventHandler = function (result) {alert('The Custom <strong>Console</strong> Component button is clicked. The <strong>com</strong>ponent IDis: ' + result.id +' and the <strong>com</strong>ponent window is: ' + (result.windowHidden ? 'hidden' :'visible'));};sforce.console.onCustom<strong>Console</strong>ComponentButtonClicked(eventHandler);Event Handler ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NameidwindowHiddenTypestringbooleanDescriptionThe ID of the custom console <strong>com</strong>ponent which includes the page.true if the custom console <strong>com</strong>ponent window is hidden after the button isclicked; false if the custom console <strong>com</strong>ponent window is visible after thebutton is clicked.68


Methods for Application-Level Custom <strong>Console</strong> ComponentsonFocusedPrimaryTab()onFocusedPrimaryTab()UsageRegisters a function to call when the focus of the browser changes to a different primary tab. This method is only available inAPI version 25.0 or later.Syntaxsforce.console.onFocusedPrimaryTab(eventHandler:Function)ArgumentsNameeventHandlerTypefunctionDescriptionJavaScript method called when the focus of the browser changes to a differentprimary tab.Sample Code–Visualforcevar eventHandler = function (result) {alert('Focus changed to a different primary tab. The primary tab ID is:'+ result.id + 'and the object Id is:' + result.objectId);};sforce.console.onFocusedPrimaryTab(eventHandler);Event Handler ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NameidobjectIdTypestringstringDescriptionThe ID of the primary tab on which the browser is focused.The object ID of the primary tab on which the browser is focused or null ifno object exists.removeFromBrowserTitleQueue()UsageRemoves a browser tab title from the list of titles, which rotates every three seconds. This method is only available in APIversion 28.0 or later.69


Methods for Application-Level Custom <strong>Console</strong> ComponentsscrollCustom<strong>Console</strong>ComponentButtonText()Syntaxsforce.console.removeFromBrowserTitleQueue( title:String, callback:Function )ArgumentsNametitlecallbackTypestringfunctionDescriptionBrowser tab title to remove.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–Visualforce {Click here to enqueue a browser titleClick here to remove browser titlevar title = 'TestTitle';function testAddToBrowserTitleQueue() {sforce.console.addToBrowserTitleQueue(title);}function testRemoveFromBrowserTitleQueue() {sforce.console.removeFromBrowserTitleQueue(title);}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:NamesuccesscallbackTypebooleanfunctionDescriptionIf true, the title was successfully removed from the browser title queue. Iffalse, the title wasn’t removed from the browser title queue.JavaScript method called upon <strong>com</strong>pletion of the method.scrollCustom<strong>Console</strong>ComponentButtonText()UsageScrolls a button’s text on an application-level custom console <strong>com</strong>ponent that’s on a page. This method is only available inAPI version 25.0 or later.Syntaxsforce.console.scrollCustom<strong>Console</strong>ComponentButtonText(interval:number, pixelsToScroll:number,isLeftScrolling:boolean, (optional)callback:Function)70


Methods for Application-Level Custom <strong>Console</strong> ComponentssetCustom<strong>Console</strong>ComponentButtonIconUrl()ArgumentsNameintervalpixelsToScrollisLeftScrollingcallbackTypenumbernumberbooleanfunctionDescriptionControls how often the button text is scrolled in milliseconds.Controls how many pixels the button text scrolls.If true, the text scrolls left. If false, the text scrolls right.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to scroll the button text on a custom console <strong>com</strong>ponentfunction testScrollCustom<strong>Console</strong>ComponentButtonText() {//Scroll the custom console <strong>com</strong>ponent button text from right to leftsforce.console.scrollCustom<strong>Console</strong>ComponentButtonText(500, 10, true,function(result){if (result.success) {alert('The text scrolling starts!');} else {alert('Could not initiate the text scrolling!');}});}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if scrolling the button text was successful; false if scrolling the buttontext wasn't successful.setCustom<strong>Console</strong>ComponentButtonIconUrl()UsageSets the button icon URL of an application-level custom console <strong>com</strong>ponent that’s on a page. This method is only availablein API version 25.0 or later.Syntaxsforce.console.setCustom<strong>Console</strong>ComponentButtonIconUrl(iconURL:String,(optional)callback:Function)71


Methods for Application-Level Custom <strong>Console</strong> ComponentssetCustom<strong>Console</strong>ComponentButtonStyle()ArgumentsNameiconUrlcallbackTypestringfunctionDescriptionA URL that points to an image that’s used as a button to launch a customconsole <strong>com</strong>ponent.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to set the custom console <strong>com</strong>ponent button iconfunction testSetCustom<strong>Console</strong>ComponentButtonIconUrl() {sforce.console.setCustom<strong>Console</strong>ComponentButtonIconUrl('http://imageserver/img.png');}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if setting the button icon URL was successful; false if setting thebutton icon URL wasn't successful.setCustom<strong>Console</strong>ComponentButtonStyle()UsageSets the style of a button used to launch an application-level custom console <strong>com</strong>ponent that’s on a page. This method is onlyavailable in API version 25.0 or later.Syntaxsforce.console.setCustom<strong>Console</strong>ComponentButtonStyle(style:String, (optional)callback:Function)ArgumentsNamestylecallbackTypestringfunctionDescriptionThe style of a button used to launch a custom console <strong>com</strong>ponent.JavaScript method called upon <strong>com</strong>pletion of the method.72


Methods for Application-Level Custom <strong>Console</strong> ComponentssetCustom<strong>Console</strong>ComponentButtonText()Sample Code–VisualforceClick here to set the style of a button used to launch a custom console <strong>com</strong>ponentfunction testSetCustom<strong>Console</strong>ComponentButtonStyle() {sforce.console.setCustom<strong>Console</strong>ComponentButtonStyle('background:red;');}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if setting the button style was successful; false if setting the buttonstyle wasn't successful.setCustom<strong>Console</strong>ComponentButtonText()UsageSets the text on a button used to launch an application-level custom console <strong>com</strong>ponent that’s on a page. This method is onlyavailable in API version 25.0 or later.Syntaxsforce.console.setCustom<strong>Console</strong>ComponentButtonText(text:String, (optional)callback:Function)ArgumentsNametextcallbackTypestringfunctionDescriptionText that’s displayed on a button used to launch a custom console <strong>com</strong>ponent.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to set the text on a button used to launch a custom console <strong>com</strong>ponentfunction testSetCustom<strong>Console</strong>ComponentButtonText() {//Change the custom console <strong>com</strong>ponent button text to 'Hello World'sforce.console.setCustom<strong>Console</strong>ComponentButtonText('Hello World');73


Methods for Application-Level Custom <strong>Console</strong> ComponentssetCustom<strong>Console</strong>ComponentPopoutable()}ResponseNamesuccessTypebooleanDescriptiontrue if setting the button text was successful; false if setting the button textwasn't successful.setCustom<strong>Console</strong>ComponentPopoutable()UsageSets a custom console <strong>com</strong>ponent to be popped out or popped into a browser. To use this method, multi-monitor <strong>com</strong>ponentsmust be turned on. For more information, see “Turn on Multi-Monitor Components for a <strong>Salesforce</strong> <strong>Console</strong>” in the onlinehelp. This method is only available in API version 30.0 or later.Syntaxsforce.console.setCustom<strong>Console</strong>ComponentPopoutable(popoutable:Boolean,(optional)callback:Function)ArgumentsNamepopoutablecallbackTypebooleanfunctionDescriptionIf true, the <strong>com</strong>ponent can be popped out or popped into a browser. If false,the <strong>com</strong>ponent cannot be popped out or popped into a browser.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to enable pop out or pop in functionality Click here to disable pop out or pop in functionalityfunction checkResult(result) {if (result.success) {alert('The method was successfully invoked.');} else {alert('Error while invoking this method. Check the browser developer consolefor more information.');}}function enablePopout() {sforce.console.setCustom<strong>Console</strong>ComponentPopoutable(true, checkResult);}function disablePopout() {74


Methods for Application-Level Custom <strong>Console</strong> ComponentssetCustom<strong>Console</strong>ComponentWindowVisible()sforce.console.setCustom<strong>Console</strong>ComponentPopoutable(false, checkResult);}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if enabling pop out or pop in functionality for the <strong>com</strong>ponent wassuccessful; false otherwise.setCustom<strong>Console</strong>ComponentWindowVisible()UsageSets the window visibility of an application-level custom console <strong>com</strong>ponent that’s on a page. This method is only availablein API version 25.0 or later.Note: If this method is called from a popped out <strong>com</strong>ponent in a <strong>Salesforce</strong> console where multi-montior <strong>com</strong>ponentsis turned on, nothing will happen. For more information, see “Turn on Multi-Monitor Components for a <strong>Salesforce</strong><strong>Console</strong>” in the online help.Syntaxsforce.console.setCustom<strong>Console</strong>ComponentWindowVisible(visible:Boolean,(optional)callback:Function)ArgumentsNamevisiblecallbackTypebooleanfunctionDescriptiontrue to make the custom console <strong>com</strong>ponent window visible, false to hidethe custom console <strong>com</strong>ponent window.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceClick here to make the custom console <strong>com</strong>ponent window visiblefunction testSetCustom<strong>Console</strong>ComponentWindowVisible() {//Make the custom console <strong>com</strong>ponent window visiblesforce.console.setCustom<strong>Console</strong>ComponentWindowVisible(true);}75


Methods for Application-Level Custom <strong>Console</strong> ComponentssetCustom<strong>Console</strong>ComponentWindowVisible()ResponseNamesuccessTypebooleanDescriptiontrue if setting the button window visibility was successful; false if settingthe button window visibility wasn't successful.76


Chapter 6Methods for Push NotificationsPush notifications are visual indicators on lists and detail pages in a <strong>Salesforce</strong> console that show when a record or field haschanged during a user’s session. For example, if two support agents are working on the same case and one agent changes thePriority, a push notification displays to the other agent so he or she notices the change and doesn’t duplicate the effort.When administrators set up a <strong>Salesforce</strong> console, they choose when push notifications display, and which objects and fieldstrigger push notifications. Developers can use push notification methods to customize push notifications beyond the defaultvisual indicators supplied by <strong>Salesforce</strong>. For example, developers can use the methods below to create personalized notificationsabout objects accessible to specific console users, thereby eliminating the need for email notifications.For more information about how to set up push notifications, see “Configure Push Notifications for a <strong>Salesforce</strong> <strong>Console</strong>” inthe <strong>Salesforce</strong> online help.Note the following when using push notification methods:• Push notification listener response is only available for the objects and fields selected to trigger push notifications for aconsole.• When a Visualforce page includes a listener added by the addPushNotificationListener() method, the page receivesnotifications. The listener receives notifications when there is an update by any user to the objects selected for triggeringconsole push notifications and the current user has access to the modified record. This functionality is slightly differentfrom push notifications set up in the <strong>Salesforce</strong> user interface in that:◊◊◊◊Listeners receive update notifications for changes made by all users.Listeners receive notifications when an object’s fields are updated or created, even if those fields aren’t selected to triggerpush notifications; and the notifications don’t include details about what changed. For example, if Status on the Caseobject is set to trigger a push notification, but Priority on the Case object changes, a listener receives a notificationthat the case changed without specifying details.Listeners don’t obey the Choose How Lists Refresh and Choose How Detail Pages Refresh pushnotifications settings in a <strong>Salesforce</strong> console.The only way to stop receiving notifications is to remove listeners using the removePushNotificationListener()method.You can use the following methods for push notifications that display in the <strong>Salesforce</strong> console:MethodaddPushNotificationListener()removePushNotificationListener()DescriptionAdds a listener for a push notification. A user can only register alistener once until he or she removes the listener, or the listener isremoved by another user. This method is only available in APIversion 26.0 or later. For more information on push notifications,see Methods for Push Notifications on page 77.Removes a listener that gets added for a push notification. Thismethod is only available in API version 26.0 or later. For more77


Methods for Push NotificationsaddPushNotificationListener()MethodDescriptioninformation on push notifications, see Methods for PushNotifications on page 77.addPushNotificationListener()UsageAdds a listener for a push notification. A user can only register a listener once until he or she removes the listener, or thelistener is removed by another user. This method is only available in API version 26.0 or later. For more information on pushnotifications, see Methods for Push Notifications on page 77.Syntaxsforce.console.addPushNotificationListener( objects: array, eventHandler:Function )ArgumentsNameobjectseventHandlerTypearrayfunctionDescriptionObjects set to receive notifications.JavaScript method called when there is a push notification.Sample Code–Visualforcevar eventHandler = function (result) {alert('There is a push notification of object: ' + result.Id);};//Add a push notification listener for Case and Accountsforce.console.addPushNotificationListener(['Case', 'Account'], eventHandler);ResponseThis method is asynchronous so it returns its response in an object in a callback method.NameidobjectTypeTypestringstringDescriptionThe object ID of the push notification.The type of object included in the push notification. For example, Account orContact.Objects available for push notifications are determined by the administratorwho set up a <strong>Salesforce</strong> console. For more information, see “Configure PushNotifications for a <strong>Salesforce</strong> <strong>Console</strong>” in the <strong>Salesforce</strong> online help.78


Methods for Push NotificationsremovePushNotificationListener()NamefieldTypeLastModifiedByIdTypestringstringDescriptionThe field of the object included in the push notification. For example, theAccount Name field on Account. Notifications occur when the field is eitherupdated or created.Fields on objects available for push notifications are determined by theadministrator who set up a <strong>Salesforce</strong> console. For more information, see“Configure Push Notifications for a <strong>Salesforce</strong> <strong>Console</strong>” in the <strong>Salesforce</strong>online help.The user ID of the user who last modified the object in the push notification.removePushNotificationListener()UsageRemoves a listener that gets added for a push notification. This method is only available in API version 26.0 or later. For moreinformation on push notifications, see Methods for Push Notifications on page 77.Syntaxsforce.console.removePushNotificationListener((optional) callback:Function )ArgumentsNamecallbackTypefunctionDescriptionA function called when the removal of the push notification listener <strong>com</strong>pletes.Sample Code–VisualforceClick here to remove push notificationfunction testRemovePushNotification() {sforce.console.removePushNotificationListener(removeSuccess);}var removeSuccess = function removeSuccess(result) {//Report whether removing the push notification listener is successfulif (result.success == true) {alert('Removing push notification was successful');} else {alert('Removing push notification wasn't successful');}};ResponseThis method is asynchronous so it returns its response in an object in a callback method.79


Methods for Push NotificationsremovePushNotificationListener()NamesuccessTypebooleanDescriptiontrue if removing the push notification listener was successful; false ifremoving the push notification listener wasn’t successful.80


Chapter 7Methods for <strong>Console</strong> EventsJavaScript can be executed when certain types of events occur in the console, such as when a user closes a tab. The followingstandard events are supported in API version 30.0 or later:EventDescriptionPayloadsforce.console.<strong>Console</strong>Event.OPEN_TAB Fired when a primary tab or subtab is • id — The ID of the opened tab.opened.• objectId — The object ID of theopened tab, if available.sforce.console.<strong>Console</strong>Event.CLOSE_TAB Fired when a primary tab or subtab with a • id — The ID of the closed tab.specified ID in the additionalParams • objectID — The object ID of theargument is closed. Or, fired when a closed tab, if available.primary tab or subtab with no specified IDis closed.You can use the following methods for console events:MethodaddEventListener()fireEvent()removeEventListener()DescriptionAdds a listener for a custom event type or a standard event typewhen the event is fired. This method adds a listener for customevent types in API version 25.0 or later; it adds a listener forstandard event types in API version 30.0 or later.Fires a custom event. This method is only available in API version25.0 or later.Removes a listener for a custom event type or a standard event type.This method removes a listener for custom event types in APIversion 25.0 or later; it removes a listener for standard event typesin API version 30.0 or later.addEventListener()UsageAdds a listener for a custom event type or a standard event type when the event is fired. This method adds a listener for customevent 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 ofstandard events, see Methods for <strong>Console</strong> Events on page 81.81


Methods for <strong>Console</strong> EventsaddEventListener()Syntaxsforce.console.addEventListener( eventType: String, eventListener:Function,(optional)additionalParams:Object )ArgumentsNameeventTypeeventListeneradditionalParamsTypestringfunctionobjectDescriptionCustom event type for which eventListener listens.JavaScript method called when an eventType is fired.Optional parameters accepted by this method. The supported properties onthis 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.Sample Code API Version 25.0 or Later–Visualforcevar listener = function (result) {alert('Message received from event: ' + result.message);};//Add a listener for the 'SampleEvent' event typesforce.console.addEventListener('SampleEvent', listener);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamemessageTypestringDescriptionThe message which is sent with the fired event.If the response is from a custom keyboard shortcut, the message includes thefollowing information on which the browser is focused, in this order:1. Object ID of the primary tab2. ID of the primary tab3. Object ID of the subtab4. ID of the subtabFor more information, see “Customize Keyboard Shortcuts for a <strong>Salesforce</strong><strong>Console</strong>” in the online help.Sample Code API Version 30.0 or Later–Visualforcevar onEnclosingPrimaryTabClose = function (result) {alert('The enclosing primary tab is about to be closed. Tab ID: ' + result.id82


Methods for <strong>Console</strong> EventsfireEvent()+ ', Object ID: ' + (result.objectId ? result.objectId : 'not available'));};//Add a listener to handle the closing of the enclosing primary tabsforce.console.getEnclosingPrimaryTabId(function (result) {if (result.id) {sforce.console.addEventListener(sforce.console.<strong>Console</strong>Event.CLOSE_TAB,onEnclosingPrimaryTabClose, { tabId : result.id });} else {alert('Could not find an enclosing primary TAB!');}});ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamemessageTypestringDescriptionThe message which is sent with the fired event.If the response is from a console event, the message includes payload detailsas described in Methods for <strong>Console</strong> Events on page 81.If the response is from a custom keyboard shortcut, the message includes thefollowing information on which the browser is focused, in this order:1. Object ID of the primary tab2. ID of the primary tab3. Object ID of the subtab4. ID of the subtabFor more information, see “Customize Keyboard Shortcuts for a <strong>Salesforce</strong><strong>Console</strong>” in the online help.fireEvent()UsageFires a custom event. This method is only available in API version 25.0 or later.Syntaxsforce.console.fireEvent( eventType:String, message:String, (optional)callback:Function )ArgumentsNameeventTypemessagecallbackTypestringstringfunctionDescriptionThe type of custom event to fire.The message which is sent with the fired event.JavaScript method called when the custom event is fired.83


Methods for <strong>Console</strong> EventsremoveEventListener()Sample Code–VisualforceClick here to fire an event of type 'SampleEvent'var callback = function(result) {if (result.success) {alert('The custom event is fired!');} else {alert('The custom event could not be fired!');}};function testFireEvent() {//Fire an event of type 'SampleEvent'sforce.console.fireEvent('SampleEvent', 'EventMessage', callback);}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing field:NamesuccessTypebooleanDescriptiontrue if firing the event is successful, false if firing the event wasn’t successful.removeEventListener()UsageRemoves a listener for a custom event type or a standard event type. This method removes a listener for custom event typesin API version 25.0 or later; it removes a listener for standard event types in API version 30.0 or later. For the list of standardevents, see Methods for <strong>Console</strong> Events on page 81.Syntaxsforce.console.removeEventListener( eventType: String, eventListener:Function,(optional)additionalParams:Object )ArgumentsNameeventTypeeventListeneradditionalParamsTypestringfunctionobjectDescriptionEvent type for which eventListener is removed.Event listener to remove.Optional parameters accepted by this method. The supported properties onthis object are tabId: The ID of the tab to remove the listener for the specifiedevent.This argument is only available in API version 30.0 or later.84


Methods for <strong>Console</strong> EventsremoveEventListener()Sample Code API Version 25.0 or Later–VisualforceClick here to remove an event listener for the 'SampleEvent' event typevar listener = function (result) {alert('Message received from event: ' + result.message);};//Add a listener for the 'SampleEvent' event typesforce.console.addEventListener('SampleEvent', listener);function testRemoveEventListener() {sforce.console.removeEventListener('SampleEvent', listener);}ResponseNoneSample Code API Version 30.0 or Later–VisualforceClick here to remove an event listener for the console 'CLOSE_TAB' eventtypevar tabId;+ ',var onEnclosingPrimaryTabClose = function (result) {alert('The enclosing primary tab is about to be closed. Tab ID: ' + result.id};Object ID: ' + (result.objectId ? result.objectId : 'not available'));//Add a listener to handle the closing of the enclosing primary tabsforce.console.getEnclosingPrimaryTabId(function (result) {if (result.id) {tabId = result.id;sforce.console.addEventListener(sforce.console.<strong>Console</strong>Event.CLOSE_TAB,onEnclosingPrimaryTabClose, { tabId : tabId });} else {alert('Could not find an enclosing primary TAB!');}});function testRemoveEventListener() {sforce.console.removeEventListener(sforce.console.<strong>Console</strong>Event.CLOSE_TAB,onEnclosingPrimaryTabClose, { tabId : tabId });}ResponseNone85


Chapter 8Methods for Live AgentLive Agent lets you connect with customers or website visitors in real time through a Web-based, text-only live chat. See“Adding Live Agent to the <strong>Salesforce</strong> <strong>Console</strong>” in the <strong>Salesforce</strong> Help for more information. You can use the followingmethods to customize Live Agent in the <strong>Salesforce</strong> <strong>Console</strong> for <strong>Service</strong>:MethodacceptChat()declineChat()endChat()getAgentInput()getAgentState()getChatLog()getChatRequests()getDetailsByChatKey()getDetailsByPrimaryTabId()getEngagedChats()getMaxCapacity()DescriptionAccepts a chat request. Available in API version 29.0 or later.Declines a chat request. Available in API version 29.0 or later.Ends a chat in which an agent is currently engaged. Available inAPI version 29.0 or later.Returns the string of text which is currently in the agent’s text inputarea in the chat log of a chat with a specific chat key. Available inAPI version 29.0 or later.Returns the agent's current Live Agent status, such as Online, Away,or Offline. Available in API version 29.0 or later.Returns the chat log of a chat associated with a specific chat key.Available in API version 29.0 or later.Returns the chat keys of the chat requests that have been assignedto an agent. Available in API version 29.0 or later.Returns the details of the chat associated with a specific chat key.Available in API version 29.0 or later.Returns the details of the chat associated with a specific primarytab ID. Available in API version 29.0 or later.Returns the chat keys of the chats in which the agent is currentlyengaged. Available in API version 29.0 or later.Returns the maximum chat capacity for the current agent, asspecified in the agent's assigned agent configuration. Available inAPI version 29.0 or later.86


Methods for Live AgentMethodonAgentSend()onAgentStateChanged()onChatCanceled()onChatCriticalWaitState()onChatDeclined()onChatEnded()onChatRequested()onChatStarted()onChatTransferredOut()onCurrentCapacityChanged()onCustomEvent()onNewMessage()onTypingUpdate()DescriptionRegisters a function to call when an agent sends a chat messagethrough the <strong>Salesforce</strong> console. This method intercepts the messageand occurs before it is sent to the chat visitor. Available in APIversion 29.0 or later.Registers a function to call when agents change their Live Agentstatus, such as from Online to Away. Available in API version 29.0or later.Registers a function to call when a chat visitor cancels a chat request.Available in API version 29.0 or later.Registers a function to call when a chat be<strong>com</strong>es critical to answeror a waiting chat is answered. Available in API version 29.0 or later.Registers a function to call when an agent declines a chat request.Available in API version 29.0 or later.Registers a function to call when an engaged chat ends. Availablein API version 29.0 or later.Registers a function to call when an agent receives a chat request.Available in API version 29.0 or later.Registers a function to call when an agent starts a new chat with acustomer. Available in API version 29.0 or later.Registers a function to call when an engaged chat is transferred outto another agent. Available in API version 29.0 or later.Registers a function to call when an agent's capacity for acceptingchats changes—for example, if an agent accepts a new chat, ends acurrently engaged chat, or otherwise changes the number of chatsto which they are assigned, or if a chat request is pushed to theirchat queue. Available in API version 29.0 or later.Registers a function to call when a custom event takes place duringa chat. Available in API version 29.0 or later.Registers a function to call when a new message is sent from acustomer, agent, or supervisor. Available in API version 29.0 orlater.Registers a function to call when the customer’s text in the chatwindow changes. If Sneak Peek is enabled, this function is calledwhenever the customer edits the text in the chat window. If Sneak87


Methods for Live AgentacceptChat()MethodDescriptionPeek is not enabled, this function is called whenever a customerstarts or stops typing in the chat window. Available in API version29.0 or later.sendCustomEvent()sendMessage()setAgentInput()setAgentState()Sends a custom event to the client-side chat window for a chat witha specific chat key. Available in API version 29.0 or later.Sends a new chat message from the agent to a chat with a specificchat key. Available in API version 29.0 or later.Sets the string of text in the agent’s text input area in the chat logof a chat with a specific chat key.Available in API version 29.0 orlater.Sets an agent's Live Agent status, such as Online, Away, or Offline.Available in API version 29.0 or later.acceptChat()UsageAccepts a chat request. Available in API version 29.0 or later.Syntaxsforce.console.chat.acceptChat(chatKey:String, (optional)callback:Function)ArgumentsNamechatKeycallbackTypeStringfunctionDescriptionThe chat key for the chat request you wish to accept.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceAccept Chatfunction testAcceptChat() {//Get the value for 'myChatKey'from the getChatRequests() or onChatRequested()methods.//These values are for example purposes onlyvar chatKey = 'myChatKey';sforce.console.chat.acceptChat(chatKey, acceptSuccess);}function acceptSuccess(result) {88


Methods for Live AgentdeclineChat()//Report whether accepting the chat was succesfulif (result.success == true) {alert('Accepting the chat was successful');} else {alert('Accepting the chat was not successful');}};ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamesuccessTypeBooleanDescriptiontrue if accepting the chat was successful; false if accepting the chat wasn’tsuccessful.declineChat()UsageDeclines a chat request. Available in API version 29.0 or later.Syntaxsforce.console.chat.declineChat(chatKey:String, (optional)callback:Function)ArgumentsNamechatKeycallbackTypeStringfunctionDescriptionThe chat key for the request you wish to decline.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceDecline Chatfunction testDeclineChat() {//Get the value for 'myChatKey'from the getChatRequests() or onChatRequested()methods.//These values are for example purposes onlyvar chatKey = 'myChatKey';sforce.console.chat.declineChat(chatKey, declineSuccess);}function declineSuccess(result) {//Report whether declining the chat was succesfulif (result.success == true) {alert('Declining the chat was successful');} else {89


Methods for Live AgentendChat()}};alert('Declining the chat was not successful');ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamesuccessTypeBooleanDescriptiontrue if declining the event was successful; false if declining the event wasn’tsuccessful.endChat()UsageEnds a chat in which an agent is currently engaged. Available in API version 29.0 or later.Syntaxsforce.console.chat.endChat(chatKey:String, (optional)callback:Function)ArgumentsNamechatKeycallbackTypeStringfunctionDescriptionThe chat key for the engaged chat you wish to end.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceEnd Chatfunction testEndChat() {//Get the value for 'myChatKey'from the getEngagedChats() or onChatStarted()methods.//These values are for example purposes onlyvar chatKey = 'myChatKey';sforce.console.chat.endChat(chatKey, endSuccess);}function endSuccess(result) {//Report whether ending the chat was succesfulif (result.success == true) {alert('Ending the chat was successful');} else {alert('Ending the chat was not successful');}};90


Methods for Live AgentgetAgentInput()ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamesuccessTypeBooleanDescriptiontrue if ending the chat was successful; false if ending the chat wasn’tsuccessful.getAgentInput()UsageReturns the string of text which is currently in the agent’s text input area in the chat log of a chat with a specific chat key.Available in API version 29.0 or later.Syntaxsforce.console.chat.getAgentInput(chatKey:String, callback:Function)ArgumentsNamechatKeycallbackTypeStringfunctionDescriptionThe chatKey associated with the chat for which to retrieve the agent’s inputtext.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceGet Agent Inputfunction testGetAgentInput() {//Get the value for 'myChatKey'from thesforce.console.chat.getDetailsByPrimaryTabId() or other chat methods.//These values are for example purposes onlyvar chatKey = 'myChatKey';sforce.console.chat.getAgentInput(chatKey, getAgentInputSuccess);}function getAgentInputSuccess(result) {//Report whether getting the agent's input was successfulif (result.success == true) {agentInput = result.text;alert('The text in the agent input is: ' + agentInput);} else {alert('Getting the agent input was not successful');}};91


Methods for Live AgentgetAgentState()ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NametextsuccessTypeStringBooleanDescriptionThe text that is currently in an agent’s text input area.true if getting the agent’s input was successful; false if getting the agent’sinput wasn’t successful.getAgentState()UsageReturns the agent's current Live Agent status, such as Online, Away, or Offline. Available in API version 29.0 or later.Syntaxsforce.console.chat.getAgentState(callback:Function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceGet Agent Statefunction testGetAgentState() {sforce.console.chat.getAgentState(function(result) {if (result.success) {alert('Agent State:' + result.state);} else {alert('getAgentState has failed');}});}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamestateTypeStringDescriptionString representing the current agent state—for example, Online, Away, orOffline.92


Methods for Live AgentgetChatLog()NamesuccessTypeBooleanDescriptiontrue if getting the agent’s Live Agent status was successful; false if gettingthe agent’s Live Agent status wasn’t successful.getChatLog()UsageReturns the chat log of a chat associated with a specific chat key. Available in API version 29.0 or later.Syntaxsforce.console.chat.getChatLog(chatKey:String, callback:Function)ArgumentsNamechatKeycallbackTypeStringfunctionDescriptionThe chatKey associated with the chat for which to retrieve the chat log.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceGet Chat Logfunction testGetChatLog() {//Get the value for 'myChatKey'from thesforce.console.chat.getDetailsByPrimaryTabId() or other chat methods.//These values are for example purposes onlyvar chatKey = 'myChatKey';sforce.console.chat.getChatLog(chatKey, getChatLogSuccess);}function getChatLogSuccess(result) {//Report whether getting the chat log was succesfulif (result.success == true) {chatLogMessage = result.messages[0].content;alert('The first message in this chatLog is: ' + chatLogMessage);} else {alert('Getting the chat log was not successful');}};ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing fields:93


Methods for Live AgentgetChatRequests()NamecustomEventsmessagessuccessTypeArray ofcustomEventobjectsArray ofmessageobjectsBooleanDescriptionAn array of custom event objects representing the custom events that occurredduring a chat.An array of chat message objects containing all of the chat messages from thechat log.true if getting the chat log was successful; false if getting the chat log wasn’tsuccessful.customEventThe customEvent object contains a single event from the chat log and the following properties:PropertysourcetypedatatimestampTypeStringStringStringDate/TimeDescriptionThe person who initiated the custom event, either the chat visitor or the agent.The type of custom event that occurred.The data of the custom event that was sent to the chat; corresponds to thedata argument of the liveagent.chasitor.sendCustomEvent()method used to send this event from the chat window.The date and time a custom event was received.messageThe message object contains a single chat message from the chat log and the following properties:PropertycontentnametypetimestampTypeStringStringStringDate/TimeDescriptionThe text content of a message in the chat log.The name of the user who sent the message in the chat log. This appears exactlyas it is displayed in the chat log.The type of message that was received, such as Agent or Visitor.The date and time the chat message was received.getChatRequests()UsageReturns the chat keys of the chat requests that have been assigned to an agent. Available in API version 29.0 or later.Syntaxsforce.console.chat.getChatRequests(callback:Function)94


Methods for Live AgentgetDetailsByChatKey()ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceGet Chat Requestsfunction testGetChatRequests() {sforce.console.chat.getChatRequests(function(result) {if (result.success) {alert('Number of Chat Requests ' + result.chatKey.length);} else {alert('getChatRequests has failed');}});}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamechatKeysuccessTypeArrayBooleanDescriptionArray of chatKey values, one for each of the current chat requests.true if getting chat requests was successful; false if getting chat requestswasn’t successful.getDetailsByChatKey()UsageReturns the details of the chat associated with a specific chat key. Available in API version 29.0 or later.Syntaxsforce.console.chat.getDetailsByChatKey(chatKey:String, callback:Function)ArgumentsNamechatKeycallbackTypeStringfunctionDescriptionThe chatKey associated with the chat for which to retrieve details.JavaScript method called upon <strong>com</strong>pletion of the method.95


Methods for Live AgentgetDetailsByChatKey()Sample Code–VisualforceGet Chat Detailsfunction testGetDetailsByChatKey() {//Get the value for 'myChatKey' from thesforce.console.chat.getDetailsByPrimaryTabId() or other chat methods.//These values are for example purposes onlyvar chatKey = 'myChatKey';sforce.console.chat.getDetailsByChatKey(chatKey, getDetailsSuccess);}function getDetailsSuccess(result) {//Report whether accepting the chat was succesfulif (result.success == true) {ipAddress = result.details.ipAddress;alert('The Visitor IP Address for this chat is: ' + ipAddress);} else {alert('Getting the details was not successful');}};ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NameprimaryTabIddetailssuccessTypeStringObjectBooleanDescriptionThe ID of the primary tab associated with the chat.An object that contains all the details for a chat associated with a particularprimary tab.true if retrieving the details was successful; false if retrieving the detailswasn’t successful.detailsThe details object contains the following properties:PropertyacceptTimebreadcrumbschatKeycustomDetailsTypeDate/TimeArray ofbreadcrumbobjectsStringArray ofcustomDetailobjectsDescriptionThe date and time an agent accepted the chat request.An array of breadcrumb objects representing a list of Web pages visitedby the visitor before and during the chat.The chat key associated with the chat.An array of customDetail objects that represent custom details thathave been passed in to this chat via the Deployment API or Pre-ChatForm API.96


Methods for Live AgentgetDetailsByChatKey()PropertygeoLocationipAddressisEndedisEngagedisPushRequestisTransferringOutliveChatButtonIdliveChatDeploymentIdnamerequestTimevisitorInfoTypeObjectStringBooleanBooleanBooleanBooleanStringStringStringDate/TimeObjectDescriptionAn object representing the details of a chat visitor’s location, derived froma geoIP lookup on the chat visitor's IP address.The IP address of the chat visitor in dot-decimal format.Specifies whether a chat has ended (true) or not (false).Specifies whether a chat is currently engaged (true) or not (false).Specifies whether a chat was routed to an agent through a push-basedrouting method such as Least Active or Most Available (true) or not(false).Specifies whether a chat is currently in the process of being transferred toanother agent (true) or not (false).The 15-digit record ID for the chat button from which the chat requestoriginated.The 15-digit record ID for the deployment from which the chat requestoriginated.The name of the chat visitor.The date and time the chat was requested.An object containing information about the visitor's web browser.breadcrumbA breadcrumb represents a Web page viewed by a chat visitor. The breadcrumb object contains the following properties:PropertylocationtimeTypeStringDate/TimeDescriptionThe URL of a Web page viewed by a chat visitor.The date and time a chat visitor visited a specific breadcrumb URL.customDetailCustom details are details have been passed into the chat through the Deployment API or Pre-Chat Form API. ThecustomDetail object contains the following properties:PropertylabelvaluetranscriptFieldsentityMapsTypeStringStringArray ofStringsArray ofentityMapobjectsDescriptionThe name of the custom detail as specified in the Deployment API or Pre-ChatForm API.The value of the custom detail as specified in the Deployment API or Pre-ChatForm API.The names of fields where the customer’s details on the chat transcript aresaved.An array of pre-created records used for mapping custom detail information.97


Methods for Live AgentgetDetailsByChatKey()entityMapEntities are records that are created when a customer starts a chat with an agent. You can use the API to auto-populate theserecords with customer details. The entityMap object contains the following properties:PropertyentityNamefieldNameisFastFillableisAutoQueryableisExactMatchableTypeStringStringBooleanBooleanBooleanDescriptionThe record to search for or create.The name of the field associated with the details.Specifies whether the value can be used to populate the field when an agentcreates or edits a record (true) or not (false) (Live Agent console only).If you’re using the Live Agent console, specifies whether to perform a a SOSLquery (in the Live Agent console) (true) or not (false) to find records witha fieldName containing the value.If you’re using the <strong>Salesforce</strong> console, specifies whether to perform a SOQLquery (in the <strong>Salesforce</strong> console) (true) or not (false) to find records witha fieldName containing the value.Specifies whether to only search for records that have fields exactly matchingthe field fieldName (true) or not (false).geoLocationThe geoLocation object represents the details of a chat visitor’s location. It contains the following properties:PropertycitycountryCodecountryNamelatitudelongitudeorganizationregionTypeStringStringStringStringStringStringStringDescriptionThe name of the chat visitor’s city.The two-digit ISO-3166 country code for the chat visitor's country.The name of chat visitor’s country.The chat visitor's approximate latitude.The chat visitor's approximate longitude.The organization name of the chat visitor's internet service provider.The chat visitor’s region, such as state or province.visitorInfoThe visitorInfo object represents information about the visitor's web browser. It contains the following properties:PropertybrowserNamelanguageoriginalReferrerscreenResolutionsessionKeyTypeStringStringStringStringStringDescriptionThe name and version of the chat visitor's web browser.The language of the chat visitor's web browser.The original URL of the Web page from which the chat visitor requested achat.The screen resolution of the chat visitor's <strong>com</strong>puter, as passed by the chatvisitor’s browser.the sessionKey of the visitor which will ultimately be stored on theLiveChatVisitor record as a unique reference to this live chat visitor98


Methods for Live AgentgetDetailsByPrimaryTabId()getDetailsByPrimaryTabId()UsageReturns the details of the chat associated with a specific primary tab ID. Available in API version 29.0 or later.Syntaxsforce.console.chat.getDetailsByPrimaryTabId(primaryTabId:String, callback:Function)ArgumentsNameprimaryTabIdcallbackTypeStringfunctionDescriptionThe ID of the primary tab associated with the chat for which to retrieve details.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceGet Chat Detailsfunction testGetDetailsByPrimaryTabId() {//Get the value for 'myPrimaryTabId'from the getPrimaryTabIds() orgetEnclosingPrimaryTabId() methods.//These values are for example purposes onlyvar primaryTabId = 'myPrimaryTabId';sforce.console.chat.getDetailsByPrimaryTabId(primaryTabId, getDetailsSuccess);}Responsefunction getDetailsSuccess(result) {//Report whether accepting the chat was succesfulif (result.success == true) {console.log(result);chatKey = result.details.chatKey;alert('The chatKey for this chat is: ' + chatKey);} else {alert('Getting the details was not Succesful');}};This method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NameprimaryTabIddetailsTypeStringObjectDescriptionThe ID of the primary tab associated with the chat.An object that contains all the details for a chat associated with a particularprimary tab.99


Methods for Live AgentgetDetailsByPrimaryTabId()NamesuccessTypeBooleanDescriptiontrue if retrieving the details was successful; false if retrieving the detailswasn’t successful.detailsThe details object contains the following properties:PropertyacceptTimebreadcrumbschatKeycustomDetailsgeoLocationipAddressisEndedisEngagedisPushRequestisTransferringOutliveChatButtonIdliveChatDeploymentIdnamerequestTimevisitorInfoTypeDate/TimeArray ofbreadcrumbobjectsStringArray ofcustomDetailobjectsObjectStringBooleanBooleanBooleanBooleanStringStringStringDate/TimeObjectDescriptionThe date and time an agent accepted the chat request.An array of breadcrumb objects representing a list of Web pages visitedby the visitor before and during the chat.The chat key associated with the chat.An array of customDetail objects that represent custom details thathave been passed in to this chat via the Deployment API or Pre-ChatForm API.An object representing the details of a chat visitor’s location, derived froma geoIP lookup on the chat visitor's IP address.The IP address of the chat visitor in dot-decimal format.Specifies whether a chat has ended (true) or not (false).Specifies whether a chat is currently engaged (true) or not (false).Specifies whether a chat was routed to an agent through a push-basedrouting method such as Least Active or Most Available (true) or not(false).Specifies whether a chat is currently in the process of being transferred toanother agent (true) or not (false).The 15-digit record ID for the chat button from which the chat requestoriginated.The 15-digit record ID for the deployment from which the chat requestoriginated.The name of the chat visitor.The date and time the chat was requested.An object containing information about the visitor's web browser.breadcrumbA breadcrumb represents a Web page viewed by a chat visitor. The breadcrumb object contains the following properties:PropertylocationtimeTypeStringDate/TimeDescriptionThe URL of a Web page viewed by a chat visitor.The date and time a chat visitor visited a specific breadcrumb URL.100


Methods for Live AgentgetDetailsByPrimaryTabId()customDetailCustom details are details that have been passed into the chat through the Deployment API or Pre-Chat Form API. ThecustomDetail object contains the following properties:PropertylabelvaluetranscriptFieldsentityMapsTypeStringStringArray ofStringsArray ofentityMapobjectsDescriptionThe name of the custom detail as specified in the Deployment API or Pre-ChatForm API.The value of the custom detail as specified in the Deployment API or Pre-ChatForm API.The names of fields where the customer’s details on the chat transcript aresaved.An array of pre-created records used for mapping the custom detail information.entityMapEntities are records that are created when a customer starts a chat with an agent. You can use the API to auto-populate theserecords with customer details. The entityMap object contains the following properties:PropertyentityNamefieldNameisFastFillableisAutoQueryableisExactMatchableTypeStringStringBooleanBooleanBooleanDescriptionThe record to search for or create.The name of the field associated the details.Specifies whether the value can be used to populate the field when an agentcreates or edits a record (true) or not (false) (Live Agent console only).If you’re using the Live Agent console, specifies whether to perform a a SOSLquery (in the Live Agent console) (true) or not (false) to find records witha fieldName containing the value.If you’re using the <strong>Salesforce</strong> console, specifies whether to perform a SOQLquery (in the <strong>Salesforce</strong> console) (true) or not (false) to find records witha fieldName containing the value.Specifies whether to only search for records that have fields exactly matchingthe field fieldName (true) or not (false).geoLocationThe geoLocation object represents the details of a chat visitor’s location. It contains the following properties:PropertycitycountryCodecountryNamelatitudelongitudeorganizationTypeStringStringStringStringStringStringDescriptionThe name of the chat visitor’s city.The two-digit ISO-3166 country code for the chat visitor's country.The name of chat visitor’s country.The chat visitor's approximate latitude.The chat visitor's approximate longitude.The organization name of the chat visitor's internet service provider.101


Methods for Live AgentgetEngagedChats()PropertyregionTypeStringDescriptionThe chat visitor’s region, such as state or province.visitorInfoThe visitorInfo object represents information about the visitor's web browser. It contains the following properties:PropertybrowserNamelanguageoriginalReferrerscreenResolutionsessionKeyTypeStringStringStringStringStringDescriptionThe name and version of the chat visitor's web browser.The language of the chat visitor's web browser.The original URL of the Web page from which the chat visitor requested achat.The screen resolution of the chat visitor's <strong>com</strong>puter, as passed by the chatvisitor’s browser.the sessionKey of the visitor which will ultimately be stored on theLiveChatVisitor record as a unique reference to this live chat visitorgetEngagedChats()UsageReturns the chat keys of the chats in which the agent is currently engaged. Available in API version 29.0 or later.Syntaxsforce.console.chat.getEngagedChats(callback:Function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceGet Engaged Chatsfunction testGetEngagedChats() {sforce.console.chat.getEngagedChats(function(result) {if (result.success) {alert('Number Engaged Chats: ' + result.chatKey.length);} else {alert('getEngagedChats has failed');}});}102


Methods for Live AgentgetMaxCapacity()ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamechatKeysuccessTypearraybooleanDescriptionArray of chatKey values, one for each of the currently engaged chats.true if getting engaged chats was successful; false if getting engaged chatswasn’t successful.getMaxCapacity()UsageReturns the maximum chat capacity for the current agent, as specified in the agent's assigned agent configuration. Availablein API version 29.0 or later.Syntaxsforce.console.chat.getMaxCapacity(callback:Function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceGet Max Capacityfunction testGetMaxCapacity() {sforce.console.chat.getMaxCapacity(function(result) {if (result.success) {alert('max capacity '+result.count);} else {alert('getMaxCapacity failed, agent my not be online');}});}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamecountTypeintegerDescriptionAgent's current, maximum chat capacity.103


Methods for Live AgentonAgentSend()NamesuccessTypebooleanDescriptiontrue if getting the agent’s capacity was successful; false if getting the agent’scapacity wasn’t successful.onAgentSend()UsageRegisters a function to call when an agent sends a chat message through the <strong>Salesforce</strong> console. This method intercepts themessage and occurs before it is sent to the chat visitor. Available in API version 29.0 or later.Note: This method is only called when an agent sends a message through the chat window interface. This methoddoesn’t apply when a sendMessage() method is called in the API.Syntaxsforce.console.chat.onAgentSend(chatKey:String, callback:Function)ArgumentsNamechatKeycallbackTypeStringfunctionDescriptionThe chatKey associated with the chat for which to call a function when theagent sends a message.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–Visualforcevar eventHandler = function (result) {var theMessage = result.content;alert('The agent is attempting to send the following message: ' + result.content);sforce.console.chat.sendMessage(chatKey, theMessage)alert('The following message has been sent: ' + theMessage);}//Get the value for 'myChatKey' from thesforce.console.chat.getDetailsByPrimaryTabId() or other chat methods.//These values are for example purposes onlyvar chatKey = 'myChatKey';sforce.console.chat.onAgentSend(chatKey, eventHandler);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamecontentTypeStringDescriptionThe text of the agent’s message.104


Methods for Live AgentonAgentStateChanged()NamenametypetimestampsuccessTypeStringStringDate/TimeBooleanDescriptionThe name of the agent who is attempting to send the message as it appears inthe chat log.The type of message that was received—for example, agent.The date and time the agent attempted to send the chat message.true if firing event was successful; false if firing event wasn’t successful.onAgentStateChanged()UsageRegisters a function to call when agents change their Live Agent status, such as from Online to Away. Available in API version29.0 or later.Syntaxsforce.console.chat.onAgentStateChanged(eventHandler:Function)ArgumentsNameeventHandlerTypefunctionDescriptionJavaScript method called when the agent's Live Agent status has changed.Sample Code–Visualforcevar eventHandler = function (result) {alert("Agent's State has Changed to: " + result.state);};sforce.console.chat.onAgentStateChanged(eventHandler);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamestatesuccessTypeStringBooleanDescriptionString that represents the agent’s current Live Agent status—for example,Online, Away, or Offline.true if firing event was successful; false if firing event wasn’t successful.105


Methods for Live AgentonChatCanceled()onChatCanceled()UsageRegisters a function to call when a chat visitor cancels a chat request. Available in API version 29.0 or later.Syntaxsforce.console.chat.onChatCanceled(callback:Function)ArgumentsNamecallbackTypefunctionDescriptionJavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–Visualforcevar eventHandler = function (result) {alert('The chat request has been canceled for this chatKey: ' + result.chatKey);}sforce.console.chat.onChatCanceled(eventHandler);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamechatKeyTypestringDescriptionThe chat key for the chat request that has been canceled.onChatCriticalWaitState()UsageRegisters a function to call when a chat be<strong>com</strong>es critical to answer or a waiting chat is answered. Available in API version 29.0or later.Syntaxsforce.console.chat.onChatCanceled(chatKey:String, callback:Function)106


Methods for Live AgentonChatDeclined()ArgumentsNamechatKeycallbackTypeStringfunctionDescriptionThe chatKey associated with the chat for which the critical wait state haschanged.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–Visualforcevar eventHandler = function (result) {alert('This chat has reached a critical wait');}//Get the value for 'myChatKey' from thesforce.console.chat.getDetailsByPrimaryTabId() or other chat methods.//These values are for example purposes onlyvar chatKey = 'myChatKey';sforce.console.chat.onChatCriticalWaitState(chatKey, eventHandler);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamestateTypeBooleanDescriptionIndicates whether the chat is in critical wait state (true) or not (false).onChatDeclined()UsageRegisters a function to call when an agent declines a chat request. Available in API version 29.0 or later.Syntaxsforce.console.chat.onChatDeclined(eventHandler:Function)ArgumentsNameeventHandlerTypefunctionDescriptionJavaScript method called when a chat request is declined.Sample Code–Visualforce107


Methods for Live AgentonChatEnded()var eventHandler = function (result) {alert('A chat request with this chatKey has been declined: ' + result.chatKey);}sforce.console.chat.onChatDeclined(eventHandler);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamechatKeysuccessTypeStringBooleanDescriptionThe chat key for the chat request that has been declined.true if firing event was successful; false if firing event wasn’t successful.onChatEnded()UsageRegisters a function to call when an engaged chat ends. Available in API version 29.0 or later.Syntaxsforce.console.chat.onChatEnded(eventHandler:Function)ArgumentsNameeventHandlerTypefunctionDescriptionJavaScript method called when an engaged chat ends.Sample Code–Visualforcevar eventHandler = function (result) {alert('A chat with this chatKey has ended: ' + result.chatKey);}sforce.console.chat.onChatEnded(eventHandler);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamechatKeysuccessTypeStringBooleanDescriptionThe chat key for the engaged chat that has ended.true if firing event was successful; false if firing event wasn’t successful.108


Methods for Live AgentonChatRequested()onChatRequested()UsageRegisters a function to call when an agent receives a chat request. Available in API version 29.0 or later.Syntaxsforce.console.chat.onChatRequested(eventHandler:Function)ArgumentsNameeventHandlerTypefunctionDescriptionJavaScript method called when a chat request is assigned to an agent.Sample Code–Visualforcevar eventHandler = function (result) {alert('There is a new in<strong>com</strong>ing chat request with this chatKey: ' +result.chatKey);}sforce.console.chat.onChatRequested(eventHandler);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamechatKeysuccessTypeStringBooleanDescriptionThe chat key for the in<strong>com</strong>ing chat request.true if firing event was successful; false if firing event wasn’t successful.onChatStarted()UsageRegisters a function to call when an agent starts a new chat with a customer. Available in API version 29.0 or later.Syntaxsforce.console.chat.onChatStarted(eventHandler:Function)109


Methods for Live AgentonChatTransferredOut()ArgumentsNameeventHandlerTypefunctionDescriptionJavaScript method called when a chat request is accepted and be<strong>com</strong>es anengaged chat.Sample Code–Visualforcevar eventHandler = function (result) {alert('A new engaged chat has started for this chatKey: ' + result.chatKey);}sforce.console.chat.onChatStarted(eventHandler);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamechatKeysuccessTypeStringBooleanDescriptionThe chat key for the chat request that has be<strong>com</strong>e an engaged chat.true if firing event was successful; false if firing event wasn’t successful.onChatTransferredOut()UsageRegisters a function to call when an engaged chat is transferred out to another agent. Available in API version 29.0 or later.Syntaxsforce.console.chat.onChatTransferredOut(eventHandler:Function)ArgumentsNameeventHandlerTypefunctionDescriptionJavaScript method called when a chat has been successfully transferred out toanother agent.Sample Code–Visualforcevar eventHandler = function (result) {alert('A chat with this chatKey has been transferred out: ' + result.chatKey);}sforce.console.chat.onChatTransferredOut(eventHandler);110


Methods for Live AgentonCurrentCapacityChanged()ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamechatKeysuccessTypeStringBooleanDescriptionThe chat key for the chat that has been transferred.true if firing event was successful; false if firing event wasn’t successful.onCurrentCapacityChanged()UsageRegisters a function to call when an agent's capacity for accepting chats changes—for example, if an agent accepts a new chat,ends a currently engaged chat, or otherwise changes the number of chats to which they are assigned, or if a chat request ispushed to their chat queue. Available in API version 29.0 or later.Syntaxsforce.console.chat.onCurrentCapacityChanged(eventHandler:Function)ArgumentsNameeventHandlerTypefunctionDescriptionJavaScript method called when the agent's capacity for accepting chats haschanged.Sample Code–Visualforcevar eventHandler = function (result) {alert('Capacity Changed. Current Requests + Engaged Chats is now: ' +result.count);}sforce.console.chat.onCurrentCapacityChanged(eventHandler);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamecountTypeintegerDescriptionThe number of chats in which the agent is currently engaged plus the numberof chat requests currently assigned to the agent.111


Methods for Live AgentonCustomEvent()NamesuccessTypeBooleanDescriptiontrue if firing event was successful; false if firing event wasn’t successful.onCustomEvent()UsageRegisters a function to call when a custom event takes place during a chat. Available in API version 29.0 or later.Syntaxsforce.console.chat.onCustomEvent(chatKey:String, type:String, callback:Function)ArgumentsNamechatKeytypecallbackTypeStringStringfunctionDescriptionThe chatKey associated with the chat for which to call a function when acustom event takes place.The name of the custom event you want to listen for. This should match thename of the custom event sent from the chat window.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–Visualforcevar eventHandler = function (result) {alert('A new custom event has been received of type ' + result.type + ' andwith data: ' + result.data );}//Get the value for 'myChatKey' from thesforce.console.chat.getDetailsByPrimaryTabId() or other chat methods.//These values are for example purposes onlyvar chatKey = 'myChatKey';var type = 'myCustomEventType';sforce.console.chat.onCustomEvent(chatKey, type, eventHandler);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NametypeTypeStringDescriptionThe type of the custom event that was sent to this chat; corresponds to thetype argument of the liveagent.chasitor.sendCustomEvent()method used to send this event from the chat window.112


Methods for Live AgentonNewMessage()NamedatasourcetimestampsuccessTypeStringStringDate/TimeBooleanDescriptionThe data of the custom event that was sent to this chat; corresponds to thedata argument of the liveagent.chasitor.sendCustomEvent()method used to send this event from the chat window.The source of the custom event that was sent to this chat; corresponds to eitherthe agent or the chat visitor, depending on who triggered the custom event.The time and date the event was received.true if firing event was successful; false if firing event wasn’t successful.onNewMessage()UsageRegisters a function to call when a new message is sent from a customer, agent, or supervisor. Available in API version 29.0or later.Syntaxsforce.console.chat.onNewMessage(chatKey:String, callback:Function)ArgumentsNamechatKeycallbackTypestringfunctionDescriptionThe chatKey associated with the chat for which to call a function when anew customer message is received.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–Visualforcevar eventHandler = function (result) {alert('There is a new message in this chat: ' + result.content);}//Get the value for 'myChatKey'from the sforce.console.chat.getDetailsByPrimaryTabId()or other chat methods.//These values are for example purposes onlyvar chatKey = 'myChatKey';sforce.console.chat.onNewMessage(chatKey, eventHandler);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamecontentTypeStringDescriptionThe text of a message in the chat log.113


Methods for Live AgentonTypingUpdate()NamenametypetimestampsuccessTypeStringStringDate/TimeBooleanDescriptionThe name of the user who sent the message. This appears exactly as it isdisplayed in the chat log.The type of message that was received, such as an Agent or Visitor message.The date and time the message was received.true if firing event was successful; false if firing event wasn’t successful.onTypingUpdate()UsageRegisters a function to call when the customer’s text in the chat window changes. If Sneak Peek is enabled, this function iscalled whenever the customer edits the text in the chat window. If Sneak Peek is not enabled, this function is called whenevera customer starts or stops typing in the chat window. Available in API version 29.0 or later.Syntaxsforce.console.chat.onTypingUpdate(chatKey:String, callback:Function)ArgumentsNamechatKeycallbackTypeStringfunctionDescriptionThe chatKey associated with the chat for which to call a function when acustomer begins typing a new message to the agent.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–Visualforcevar eventHandler = function (result) {alert('There is a new typing update in this chat');}//Get the value for 'myChatKey'from the sforce.console.chat.getDetailsByPrimaryTabId()or other chat methods.//These values are for example purposes onlyvar chatKey = 'myChatKey';sforce.console.chat.onTypingUpdate(chatKey, eventHandler);ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NameisTypingTypeBooleanDescriptionIndicates whether a chat visitor is typing (true) or not (false).114


Methods for Live AgentsendCustomEvent()NamesneakPeeksuccessTypeStringBooleanDescriptionThe text the chat visitor is currently typing into their input box in the chatwindow. This is visible only if Sneak Peek is enabled for the agent.true if firing event was successful; false if firing event wasn’t successful.sendCustomEvent()UsageSends a custom event to the client-side chat window for a chat with a specific chat key. Available in API version 29.0 or later.Syntaxsforce.console.chat.sendCustomEvent(chatKey:String, type:String, data:String,callback:Function)ArgumentsNamechatKeytypedatacallbackTypeStringStringStringfunctionDescriptionThe chatKey associated with the chat to which to send a custom event.The name of the custom event you want to send to the chat window.Additional data you want to send to the chat window along with the customevent.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceSend Custom Eventfunction testSendCustomEvent() {//Get the value for 'myChatKey'from thesforce.console.chat.getDetailsByPrimaryTabId() or other chat methods.//These values are for example purposes onlyvar chatKey = 'myChatKey';var type = 'myCustomEventType'var data = 'myCustomEventData'sforce.console.chat.sendCustomEvent(chatKey, type, data, sendCustomEventSuccess);}function sendCustomEventSuccess(result) {//Report whether sending the custom event was successfulif (result.success == true) {alert('The customEvent has been sent');} else {alert('Sending the customEvent was not successful');}};115


Methods for Live AgentsendMessage()ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamesuccessTypeBooleanDescriptiontrue if sending the custom event was successful; false if sending the customevent wasn’t successful.sendMessage()UsageSends a new chat message from the agent to a chat with a specific chat key. Available in API version 29.0 or later.Syntaxsforce.console.chat.sendMessage(chatKey:String, message:String, callback:Function)ArgumentsNamechatKeymessagecallbackTypeStringStringfunctionDescriptionThe chatKey of the chat where the agent’s message is sent.The message you would like to send from the agent to the customer in a chat.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceSend Messagefunction testSendMessage() {//Get the value for 'myChatKey'from thesforce.console.chat.getDetailsByPrimaryTabId() or other chat methods.//These values are for example purposes onlyvar chatKey = 'myChatKey';var text ='This is sample text to send as a message';sforce.console.chat.sendMessage(chatKey, text, sendMessageSuccess);}function sendMessageSuccess(result) {//Report whether getting the chat log was successfulif (result.success == true) {alert('Message Sent');} else {alert('Sending the message was not successful');}};116


Methods for Live AgentsetAgentInput()ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamesuccessTypeBooleanDescriptiontrue if sending the message was successful; false if sending the messagewasn’t successful.setAgentInput()UsageSets the string of text in the agent’s text input area in the chat log of a chat with a specific chat key.Available in API version29.0 or later.Syntaxsforce.console.chat.setAgentInput(chatKey:String, text:String, callback:Function)ArgumentsNamechatKeytextcallbackTypeStringStringfunctionDescriptionThe chatKey associated with the chat for which to set the agent’s input text.The string of text which you want to set into an agent's input.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceSet Agent Inputfunction testSetAgentInput() {//Get the value for 'myChatKey'from thesforce.console.chat.getDetailsByPrimaryTabId() or other chat methods.//These values are for example purposes onlyvar chatKey = 'myChatKey';var text = 'This is example text to set the agent input'sforce.console.chat.setAgentInput(chatKey, text, setAgentInputSuccess);}function setAgentInputSuccess(result) {//Report whether setting the agent's input was succesfulif (result.success == true) {alert('The text in the agent input has been updated');} else {alert('Setting the agent input was not Succesful');}117


Methods for Live AgentsetAgentState()};ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:NamesuccessTypeBooleanDescriptiontrue if setting the agent’s input was successful; false if setting the agent’sinput wasn’t successful.setAgentState()UsageSets an agent's Live Agent status, such as Online, Away, or Offline. Available in API version 29.0 or later.Syntaxsforce.console.chat.setAgentState(state:String, (optional)callback:Function)ArgumentsNamestatecallbackTypeStringfunctionDescriptionLive Agent status you want to set the agent to—for example, Online, Away,or Offline.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–VisualforceSet Agent Status toOnlinefunction testSetAgentState(state) {sforce.console.chat.setAgentState(state, function(result) {if (result.success) {alert('Agent State Set to Online');} else {alert('setAgentState has failed');}});}ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing properties:118


Methods for Live AgentMethods for Live Agent Chat VisitorsNamesuccessTypeBooleanDescriptiontrue if setting the agent’s Live Agent status was successful; false if settingthe agent’s Live Agent status wasn’t successful.Methods for Live Agent Chat VisitorsYou can use the following methods to customize the chat visitor experience for Live Agent in a custom Visualforce chatwindow:Methodchasitor.addCustomEventListener()chasitor.getCustomEvents()chasitor.sendCustomEvent()DescriptionRegisters a function to call when a custom event is received in thechat window. Available in API version 29.0 or later.Retrieves a list of custom events that have been received in this chatwindow during this chat session. Available in API version 29.0 orlater.Sends a custom event to the agent console of the agent who iscurrently chatting with a customer. Available in API version 29.0or later.chasitor.addCustomEventListener()UsageRegisters a function to call when a custom event is received in the chat window. Available in API version 29.0 or later.Syntaxliveagent.chasitor.addCustomEventListener(type:String, callback:Function)ArgumentsNametypecallbackTypestringfunctionDescriptionThe type of custom event you want to listen for.JavaScript method called upon <strong>com</strong>pletion of the method.Sample Code–Visualforcefunction testAddCustomEventListener() {//These values are for example purposes onlyvar type = 'myCustomEventType'liveagent.chasitor.addCustomEventListener(type, customEventReceived)}119


Methods for Live Agentchasitor.getCustomEvents()function customEventReceived(result) {eventType = result.getType();eventData = result.getData();alert('A custom event of type: ' + eventType + ' has been received with thefollowing data: ' + eventData);};testAddCustomEventListener();ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing methods:NamegetTypegetDatagetSourcegetDateTypemethodmethodmethodmethodDescriptionAccesses the type of the custom event that was sent to this chat window.Returns the type argument of thesforce.console.chat.sendCustomEvent() method used to send thisevent.Accesses the data of the custom event that was sent to this chat window.Returns the data argument of thesforce.console.chat.sendCustomEvent() method used to send thisevent.Accesses the source of the custom event that was sent to this chat window—forexample, agent or chat visitor.Accesses the date of the custom event that was sent to this chat window.Returns the date and time the event was received.chasitor.getCustomEvents()UsageRetrieves a list of custom events that have been received in this chat window during this chat session. Available in API version29.0 or later.Syntaxliveagent.chasitor.getCustomEvents()Sample Code–VisualforceGet Custom Eventsfunction testGetCustomEvents() {events = liveagent.chasitor.getCustomEvents();eventsCount = events.length;alert('The following number of custom events have occurred: ' + eventsCount);};120


Methods for Live Agentchasitor.sendCustomEvent()ResponseThis method is asynchronous so it returns its response in an object in a callback method. The response object contains thefollowing methods and properties:NameeventsgetTypegetDatagetSourcegetDateTypeArray ofevent objectsmethodmethodmethodmethodDescriptionAn array of event objects. Each object represents a custom event that hasoccurred in this chat. Data on each message object can be accessed by thefollowing methods:• getType()• getData()• getSource()• getDate()Accesses the type of the custom event that was sent to this chat window.Returns the type argument of thesforce.console.chat.sendCustomEvent() method used to send thisevent.Accesses the data of the custom event that was sent to this chat window.Returns the data argument of thesforce.console.chat.sendCustomEvent() method used to send thisevent.Accesses the source of the custom event that was sent to this chat window—forexample, agent or chat visitor.Accesses the date of the custom event that was sent to this chat window.Returns the date and time the event was received.chasitor.sendCustomEvent()UsageSends a custom event to the agent console of the agent who is currently chatting with a customer. Available in API version29.0 or later.Syntaxliveagent.chasitor.sendCustomEvent(type:String, data:String)ArgumentsNametypedataTypestringstringDescriptionThe name of the custom event to send to the agent console.Additional data you want to send to the agent console along with the customevent.Sample Code–VisualforceSend Custom Event121


Methods for Live Agentchasitor.sendCustomEvent()function testSendCustomEvent() {type = 'myCustomEventType';data = 'myCustomEventData';liveagent.chasitor.sendCustomEvent(type, data);alert('The custom event has been sent');};ResponseThis method returns no responses.122


GlossaryA |B |C |D |E |F |G |H |I |J |K |L |M |N |O |P |Q |R |S |T |U |V |W |X |Y |ZAAdministrator (System Administrator)One or more individuals in your organization who can configure and customize the application. Users assigned to theSystem Administrator profile have administrator privileges.Application Programming Interface (API)The interface that a <strong>com</strong>puter system, library, or application provides to allow other <strong>com</strong>puter programs to requestservices from it and exchange data.Asynchronous CallsBA call that does not return results immediately because the operation may take a long time. Calls in the Metadata APIand Bulk API are asynchronous.Boolean OperatorsCYou can use Boolean operators in report filters to specify the logical relationship between two values. For example, theAND operator between two values yields search results that include both values. Likewise, the OR operator betweentwo values yields search results that include either value.Custom LinksDCustom links are URLs defined by administrators to integrate your <strong>Salesforce</strong> data with external websites and back-officesystems. Formerly known as Web links.DatabaseAn organized collection of information. The underlying architecture of the Force.<strong>com</strong> platform includes a databasewhere your data is stored.Database TableA list of information, presented with rows and columns, about the person, thing, or concept you want to track. See alsoObject.Developer EditionA free, fully-functional <strong>Salesforce</strong> organization designed for developers to extend, integrate, and develop with theForce.<strong>com</strong> platform. Developer Edition accounts are available on developer.force.<strong>com</strong>.123


GlossaryDeveloper ForceEThe Developer Force website at developer.force.<strong>com</strong> provides a full range of resources for platform developers, includingsample code, toolkits, an online developer <strong>com</strong>munity, and the ability to obtain limited Force.<strong>com</strong> platform environments.Enterprise EditionFFieldA <strong>Salesforce</strong> edition designed for larger, more <strong>com</strong>plex businesses.A part of an object that holds a specific piece of information, such as a text or currency value.Field-Level SecuritySettings that determine whether fields are hidden, visible, read only, or editable for users. Available in Enterprise,Unlimited, Performance, and Developer Editions only.Force.<strong>com</strong>GThe salesforce.<strong>com</strong> platform for building applications in the cloud. Force.<strong>com</strong> <strong>com</strong>bines a powerful user interface,operating system, and database to allow you to customize and deploy applications in the cloud for your entire enterprise.Group EditionHA product designed for small businesses and workgroups with a limited number of users.No Glossary items for this entry.IIDSee <strong>Salesforce</strong> Record ID.InstanceThe cluster of software and hardware represented as a single logical server that hosts an organization's data and runstheir applications. The Force.<strong>com</strong> platform runs on multiple instances, but data for any single organization is alwaysconsolidated on a single instance.Interaction LogJAn area in a <strong>Salesforce</strong> console where you can jot notes about the main record you're working on without clicking abutton, viewing a new tab, or scrolling to the Notes & Attachments related list. Interaction logs are archived on theActivity History related list for easy review and retrieval. Administrators can customize interaction logs to include taskfields.No Glossary items for this entry.KNo Glossary items for this entry.124


GlossaryLLogged-in UserMIn a SOAP API context, the username used to log into <strong>Salesforce</strong>. Client applications run with the permissions andsharing of the logged-in user. Also referred to as an integration user.MetadataInformation about the structure, appearance, and functionality of an organization and any of its parts. Force.<strong>com</strong> usesXML to describe metadata.MultitenancyNAn application model where all users and apps share a single, <strong>com</strong>mon infrastructure and code base.Navigation TabOObjectA tab with a drop-down button in a <strong>Salesforce</strong> console that lets you select and view object home pages.An object allows you to store information in your <strong>Salesforce</strong> organization. The object is the overall definition of the typeof information you are storing. For example, the case object allow you to store information regarding customer inquiries.For each object, your organization will have multiple records that store the information about specific instances of thattype of data. For example, you might have a case record to store the information about Joe Smith's training inquiry andanother case record to store the information about Mary Johnson's configuration issue.OrganizationPA deployment of <strong>Salesforce</strong> with a defined set of licensed users. An organization is the virtual space provided to anindividual customer of salesforce.<strong>com</strong>. Your organization includes all of your data and applications, and is separate fromall other organizations.Personal EditionProduct designed for individual sales representatives and single users.Platform EditionA <strong>Salesforce</strong> edition based on Enterprise, Unlimited, or Performance Edition that does not include any of the standard<strong>Salesforce</strong> CRM apps, such as Sales or <strong>Service</strong> & Support.Primary TabA tab in a <strong>Salesforce</strong> console that displays the main item to work on, such as an account.Production OrganizationA <strong>Salesforce</strong> organization that has live users accessing data.Professional EditionQA <strong>Salesforce</strong> edition designed for businesses who need full-featured CRM functionality.No Glossary items for this entry.125


GlossaryRRecordSA single instance of a <strong>Salesforce</strong> object. For example, “John Jones” might be the name of a contact record.<strong>Salesforce</strong> Record IDA unique 15- or 18-character alphanumeric string that identifies a single record in <strong>Salesforce</strong>.Sandbox OrganizationA nearly identical copy of a <strong>Salesforce</strong> production organization. You can create multiple sandboxes in separate environmentsfor a variety of purposes, such as testing and training, without <strong>com</strong>promising the data and applications in your productionenvironment.<strong>Salesforce</strong> <strong>Console</strong>The <strong>Salesforce</strong> console is designed for users in fast-paced environments who need to find, update, and create recordsquickly. It improves upon the Agent <strong>Console</strong> in the <strong>Console</strong> tab by displaying records and related items as tabs on onescreen.Session IDAn authentication token that is returned when a user successfully logs in to <strong>Salesforce</strong>. The Session ID prevents a userfrom having to log in again every time he or she wants to perform another action in <strong>Salesforce</strong>. Different from a recordID or <strong>Salesforce</strong> ID, which are terms for the unique ID of a <strong>Salesforce</strong> record.Session TimeoutSharingThe period of time after login before a user is automatically logged out. Sessions expire automatically after a predeterminedlength of inactivity, which can be configured in <strong>Salesforce</strong> from Setup by clicking Security Controls. The default is 120minutes (two hours). The inactivity timer is reset to zero if a user takes an action in the Web interface or makes an APIcall.Allowing other users to view or edit information you own. There are different ways to share data:• Sharing Model—defines the default organization-wide access levels that users have to each other’s information andwhether to use the hierarchies when determining access to data.• Role Hierarchy—defines different levels of users such that users at higher levels can view and edit information ownedby or shared with users beneath them in the role hierarchy, regardless of the organization-wide sharing model settings.• Sharing Rules—allow an administrator to specify that all information created by users within a given group or roleis automatically shared to the members of another group or role.• Manual Sharing—allows individual users to share records with other users or groups.• Apex-Managed Sharing—enables developers to programmatically manipulate sharing to support their application’sbehavior. See Apex-Managed Sharing.SOAP (Simple Object Access Protocol)A protocol that defines a uniform way of passing XML-encoded data.Standard ObjectA built-in object included with the Force.<strong>com</strong> platform. You can also build custom objects to store information that isunique to your app.System LogPart of the Developer <strong>Console</strong>, a separate window console that can be used for debugging code snippets. Enter the codeyou want to test at the bottom of the window and click Execute. The body of the System Log displays system resource126


Glossaryinformation, such as how long a line took to execute or how many database calls were made. If the code did not run to<strong>com</strong>pletion, the console also displays debugging information.TTest OrganizationTriggerUA <strong>Salesforce</strong> organization used strictly for testing. See also Sandbox Organization.A piece of Apex that executes before or after records of a particular type are inserted, updated, or deleted from thedatabase. Every trigger runs with a set of context variables that provide access to the records that caused the trigger tofire, and all triggers run in bulk mode—that is, they process several records at once, rather than just one record at a time.Unlimited EditionUnlimited Edition is salesforce.<strong>com</strong>'s solution for maximizing CRM success and extending that success across the entireenterprise through the Force.<strong>com</strong> platform.URL (Uniform Resource Locator)VVersionThe global address of a website, document, or other resource on the Internet. For example, http://www.salesforce.<strong>com</strong>.A number value that indicates the release of an item. Items that can have a version include API objects, fields and calls;Apex classes and triggers; and Visualforce pages and <strong>com</strong>ponents.VisualforceWA simple, tag-based markup language that allows developers to easily define custom pages and <strong>com</strong>ponents for appsbuilt on the platform. Each tag corresponds to a coarse or fine-grained <strong>com</strong>ponent, such as a section of a page, a relatedlist, or a field. The <strong>com</strong>ponents can either be controlled by the same logic that is used in standard <strong>Salesforce</strong> pages, ordevelopers can associate their own logic with a controller written in Apex.Web <strong>Service</strong>A mechanism by which two applications can easily exchange data over the Internet, even if they run on different platforms,are written in different languages, or are geographically remote from each other.Web <strong>Service</strong>s APIA Web services application programming interface that provides access to your <strong>Salesforce</strong> organization's information.See also SOAP API and Bulk API.Wrapper ClassA class that abstracts <strong>com</strong>mon functions such as logging in, managing sessions, and querying and batching records. Awrapper class makes an integration more straightforward to develop and maintain, keeps program logic in one place,and affords easy reuse across <strong>com</strong>ponents. Examples of wrapper classes in <strong>Salesforce</strong> include theAJAX <strong>Toolkit</strong>, whichis a JavaScript wrapper around the <strong>Salesforce</strong> SOAP API, wrapper classes such as CCritical Section in the CTIAdapter for <strong>Salesforce</strong> CRM Call Center, or wrapper classes created as part of a client integration application thataccesses <strong>Salesforce</strong> using the SOAP API.127


GlossaryWSDL (Web <strong>Service</strong>s Description Language) FileXAn XML file that describes the format of messages you send and receive from a Web service. Your developmentenvironment's SOAP client uses the <strong>Salesforce</strong> Enterprise WSDL or Partner WSDL to <strong>com</strong>municate with <strong>Salesforce</strong>using the SOAP API.No Glossary items for this entry.YNo Glossary items for this entry.ZNo Glossary items for this entry.128


IndexIndexAacceptChat() 88addCustomEventListener() 119addEventListener() 81addPushNotificationListener() 78addToBrowserTitleQueue() 63Asynchronous calls 7Authentication 8BBackward <strong>com</strong>patibility 2Best practices 9blinkCustom<strong>Console</strong>ComponentButtonText() 64CcloseTab() 13Connecting to the <strong>Toolkit</strong> 7Custom console <strong>com</strong>ponents 9, 62DdeclineChat() 89Domainsmultiple 1whitelist 1EEnd-of-life 3endChat() 90events 81FfireEvent() 83focusPrimaryTabById() 14focusPrimaryTabByName() 15focusSubtabById() 16focusSubtabByNameAndPrimaryTabID() 17focusSubtabByNameAndPrimaryTabName() 19Force.<strong>com</strong> canvas 8Ggenerate<strong>Console</strong>Url() 20getAgentInput() 91getAgentState() 92getCallAttachedData() 56getCallObjectIds() 57getChatLog() 93getChatRequests() 94getCustomEvents() 120getDetailsByChatKey() 95getDetailsByPrimaryTabId() 99getEnclosingPrimaryTabId() 21getEnclosingPrimaryTabObjectId() 22getEnclosingTabId() 23getEngagedChats() 102getFocusedPrimaryTabId() 24getFocusedPrimaryTabObjectId() 25getFocusedSubtabId() 26getFocusedSubtabObjectId() 26getMaxCapacity() 103getPageInfo() 27getPrimaryTabIds() 28getSubtabIds() 29getTabLink() 30Iintegration.js 7Introduction 1isCustom<strong>Console</strong>ComponentPoppedOut() 65isCustom<strong>Console</strong>ComponentWindowHidden() 66isIn<strong>Console</strong>() 31isInCustom<strong>Console</strong>Component() 67LLive Agent 86, 119MMethodsacceptChat() 88addCustomEventListener() 119addEventListener() 81addPushNotificationListener() 78addToBrowserTitleQueue() 63app-level custom console <strong>com</strong>ponents 62blinkCustom<strong>Console</strong>ComponentButtonText() 64call center 56closeTab() 13<strong>com</strong>puter-telephony integration (CTI) 56console events 81custom console <strong>com</strong>ponents 62declineChat() 89endChat() 90events 81fireEvent() 83focusPrimaryTabById() 14focusPrimaryTabByName() 15focusSubtabById() 16129


IndexMethods (continued)focusSubtabByNameAndPrimaryTabId() 17focusSubtabByNameAndPrimaryTabName() 19generate<strong>Console</strong>Url() 20getAgentInput() 91getAgentState() 92getCallAttachedData() 56getCallObjectIds() 57getChatLog() 93getChatRequests() 94getCustomEvents() 120getDetailsByChatKey() 95getDetailsByPrimaryTabId() 99getEnclosingPrimaryTabId() 21getEnclosingPrimaryTabObjectId() 22getEnclosingTabId() 23getEngagedChats() 102getFocusedPrimaryTabId() 24getFocusedPrimaryTabObjectId() 25getFocusedSubtabId() 26getFocusedSubtabObjectId() 26getMaxCapacity() 103getPageInfo() 27getPrimaryTabIds() 28getSubtabIds() 29getTabLink() 30isCustom<strong>Console</strong>ComponentPoppedOut() 65isCustom<strong>Console</strong>ComponentWindowHidden() 66isIn<strong>Console</strong>() 31isInCustom<strong>Console</strong>Component() 67Live Agent 86, 119onAgentSend() 104onAgentStateChanged() 105onCallBegin() 58onCallEnd() 59onChatCanceled() 106onChatCriticalWaitState() 106onChatDeclined() 107onChatEnded() 108onChatRequested() 109onChatTransferredOut() 110onCurrentCapacityChanged() 111onCustom<strong>Console</strong>ComponentButtonClicked() 68onCustomEvent() 112onEnclosingTabRefresh() 32onFocusedPrimaryTab() 69onFocusedSubtab() 33onNewMessage() 113onTabSave() 34onTypingUpdate() 114open<strong>Console</strong>Url() 35openPrimaryTab() 36openSubtab() 38openSubtabByPrimaryTabName() 39primary tabs 10push notifications 77Methods (continued)refreshPrimaryTabById() 41refreshPrimaryTabByName() 42refreshSubtabById() 43refreshSubtabByNameAndPrimaryTabId() 45refreshSubtabByNameAndPrimaryTabName() 46removeEventListener() 84removeFromBrowserTitleQueue() 69removePushNotificationListener() 79resetSessionTimeOut() 47scrollCustom<strong>Console</strong>ComponentButtonText() 70sendCTIMessage() 60sendCustomEvent() 115, 121sendMessage() 116setAgentInput() 117setAgentState() 118setCustom<strong>Console</strong>ComponentButtonIconUrl() 71setCustom<strong>Console</strong>ComponentButtonStyle() 72setCustom<strong>Console</strong>ComponentButtonText() 73setCustom<strong>Console</strong>ComponentPopoutable() 74setCustom<strong>Console</strong>ComponentWindowVisible() 75setTabIcon() 49setTabLink() 51setTabStyle() 51setTabTextStyle() 52setTabTitle() 54setTabUnsavedChanges() 48subtabs 10OOAuth 8onAgentSend() 104onAgentStateChanged() 105onCallBegin() 58onCallEnd() 59onChatCanceled() 106onChatCriticalWaitState() 106onChatDeclined() 107onChatEnded() 108onChatRequested() 109onChatTransferredOut() 110onCurrentCapacityChanged() 111onCustom<strong>Console</strong>ComponentButtonClicked() 68onCustomEvent() 112onEnclosingTabRefresh() 32onFocusedPrimaryTab() 69onFocusedSubtab() 33onNewMessage() 113onTabSave() 34onTypingUpdate() 114open<strong>Console</strong>Url() 35openPrimaryTab() 36openSubtab() 38openSubtabByPrimaryTabName() 39Other resources 3130


IndexPPush notifications 77RrefreshPrimaryTabById() 41refreshPrimaryTabByName() 42refreshSubtabById() 43refreshSubtabByNameAndPrimaryTabId() 45refreshSubtabByNameAndPrimaryTabName() 46removeEventListener() 84removeFromBrowserTitleQueue() 69removePushNotificationListener() 79resetSessionTimeOut() 47Resources for developers 3S<strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong>Using 7Sample page 4scrollCustom<strong>Console</strong>ComponentButtonText() 70sendCTIMessage() 60sendCustomEvent() 115, 121sendMessage() 116setAgentInput() 117setAgentState() 118setCustom<strong>Console</strong>ComponentButtonIconUrl() 71setCustom<strong>Console</strong>ComponentButtonStyle() 72setCustom<strong>Console</strong>ComponentButtonText() 73setCustom<strong>Console</strong>ComponentPopoutable() 74setCustom<strong>Console</strong>ComponentWindowVisible() 75setTabIcon() 49setTabLink() 51setTabStyle() 51setTabTextStyle() 52setTabTitle() 54setTabUnsavedChanges() 48Support policy 2TTypographical conventions 3WWhen to use the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> 1Working with the <strong>Salesforce</strong> <strong>Console</strong> <strong>Integration</strong> <strong>Toolkit</strong> 7131

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!