I have javascript code that creates an instance of a javascript function whenever a call comes into a cti integration.

The JavaScript function does a screenpop based on call information, and gets the ID of the tab using the sforce.console.onFocusedSubtab event. This tab is then associated with the call, and if a user changes call we change to the relevant tab

Here is the method that registers for the event:

function screenPop() {
    searchCriteria = getScreenPopConfigurationItem(call);

    if (searchCriteria) {
      //Invokes API method

      if (searchCriteria.isScreenPop) {
        sforce.interaction.screenPop('/' + searchCriteria.searchValue, true, getSearchMatches);
      else {
        sforce.interaction.searchAndScreenPop(searchCriteria.searchValue, '', 'inbound', getSearchMatches);

And the callback method that sets the tabId

function storeTabId(focusTabEventArgs){
    if(!tabId && focusTabEventArgs.objectId){
      tabId = focusTabEventArgs.id;
      salesforceObjectId = focusTabEventArgs.objectId;

I only want to fire this event once per instance (call), so I would like to unregister from the event once it is fired, so it will not be called for each instance when other calls come in.

I don't see any way to do this, is it possible?

  • 2
    Instead of describing what the code does, why not edit your question to include a minimal example instead? – battery.cord Mar 10 '17 at 16:10
  • I didn't think a code example would add anything. My question is simple, is it possible to unregister from the sforce.console.onFocusedSubtab event. The rest of the question just gives context – Neil Mar 10 '17 at 16:34

There isn't a way to unregister that event through the toolkit.

One option might be creating a no-op function and setting that as the listener once you've handled the event? So inside of the storeTabId function once it's done running you could do something like


I haven't tested that but in theory it should work.

Another option which is perhaps cleaner is to use the toolkit's support for custom events. Create your own event which fires during the onFocusedSubtab callback, and have the customer listener that you can add/remove at will when necessary. It adds another layer of abstraction to what you're doing but then you can do it with code which makes sense when you read it and uses supported functions.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.