Here is a small experiment as a proof of concept to emit events from lightning component and handle in VF
<aura:component>
<div> Hello World !!!! </div>
<aura:registerEvent name="myevent" type="c:myEvent" />
<ui:button label="fireEvent" press="{!c.fireevent}" />
</aura:component>
The JS controller file
({
fireevent: function(component, event, helper) {
var myEvent = $A.get("e.c:myEvent");
myEvent.setParams({"data":"Test"});
myEvent.fire();
}
})
The Event file
<aura:event type="APPLICATION">
<aura:attribute type="string" name="data" />
</aura:event>
The application file
<aura:application access="GLOBAL" extends="ltng:outApp">
<aura:dependency resource="c:myComponent" />
</aura:application>
The visualforce where event is handled
<apex:page showHeader="false" sidebar="false">
<apex:includeLightning />
<div id="lightning"> Hello world VF ..!!! </div>
<script>
$Lightning.use("c:myEventApp", function() {
$Lightning.createComponent("c:myComponent", {}, "lightning", function(){
$A.eventService.addHandler({ "event": "c:myEvent", "handler" : visualForceFunction});
});
});
</script>
<script>
var visualForceFunction = function(event){
var myEventData = event.getParam("data");
console.log(myEventData);
};
</script>
DISCLAMIER : I have not tried inside service console but this should help you get started .For ISV apps since this is not documented anywhere ,consult SFDC security review team or salesforce lightning component product team to see if this is right way of doing this .
It turns out there is a getEnclosingTabId()
method that's not listed in the top level of the workspace API methods.
I ended up adding logic comparing the enclosing tab to the focused tab, like so:
var focusedTabId = event.getParam('currentTabId');
var workspaceAPI = component.find("workspace");
workspaceAPI.getEnclosingTabId().then(function(tabId) {
if (focusedTabId == tabId) {
System.debug('The current tab is the one being focused!');
}
})
.catch(function(error) {
console.log(error);
});
Best Answer
With Summer 18 Release, you can open custom lightning components in a new tab.
If You are trying to open
MyComponent.cmp
in a new tab/subtab, implement this interfacelightning:isUrlAddressable
in that component.In the other Component, in which you are trying to fire the tab opening event.