function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gen EsysGen Esys 

How do I close a tab in Lightning Console in a visualforce page?

I'm trying to have our console app work in both SFDC Classic and Lightning (it's a requirement).

I'm trying to close a VisualForce page via some JavaScript code. With Classic Console I did the following:

sforce.console.closeTab(id, callback);

There's some equivalent in Lightning here: https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_lightning_closeTab.htm

But this is called from within a Lightning component. How do I do it from a VisualForce page?

There are also lots of other methods I'd like to use, but I can't see to get the 'hook' that I need.
Gen EsysGen Esys
I should mention that I'm using the OpenCTI library as per https://developer.salesforce.com/docs/atlas.en-us.api_cti.meta/api_cti/sforce_api_cti_sample_js.htm.

This example shows both the Salesforce Classic and Lightning Experience versions.
Gen EsysGen Esys
After many days and way too much time spent of this, OpenCTI is broken for Lightning.
 
I’ve got an example below. You can see a “Mark Done” and a “Release” button which are components added to the Task page. You can also see OpenCTI panel open and there is a Lightning component in it.
 
Open CTI Lightning Example

These are the two main issues:
  • Events can’t be sent from the mark done/release buttons to the OpenCTI component. This means that no custom buttons may be added.
  • The OpenCTI component can’t close tabs or detect primary tabs to set subtabs. There have been extensive changes in the Lightning OpenCTI API that reflects this.
Fortunately we can still do the following:
  • Screen pops.
  • The search screen can be used to bring up a contact.
  • Case and new Tasks can be created but as primary tabs.
The main technical issue is that the OpenCTI control starts off as a VisualForce page and then loads Lightning components inside it. Even the SFDC demo softphone does this.
 
The Lightning application which I’ve set up loads up in the Visual Force context:
 
https://camster-dev-ed--c.ap1.visual.force.com/apex/LightningCRMConnector?mode=Lightning&isdtp=vw&sfdcIframeOrigin=https%3A%2F%2Fcamster-dev-ed.lightning.force.com
 
The mark done component is loaded in here: https://camster-dev-ed.lightning.force.com/auraFW/resources/nRhh35vBDuL0P3mlbcWPkg/lockerservice/components/c/MarkDoneComponent.js
 
You’ll notice the host name is different - camster-dev-ed--c.ap1.visual.force.com versus camster-dev-ed.lightning.force.com.
 
So SFDC are making use of iframes with different domain names. This makes sending events between the two impossible (the browser enforces this).
 
I’m surprised at how badly Salesforce have managed to stuff this up.
Anbu Thiagarajan 10Anbu Thiagarajan 10
Were you able to solve the issue of closing the Tab from VF?
Gen EsysGen Esys
No, there's still nothing available. Lightning is still very broken for OpenCTI.