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 .
You're trying to pass your variables by leaking them into the global state. Bad idea. Basically:
var function1 = function (inputValue) {
unscopedVar = inputValue;
}
var function2 = function () {
// use unscopedVar
}
Don't do that, it's bad practice. And in this case, it's not even going to work, because the variables are synchronous in function1
and asynchronous in function2
. So the first step in getting your code working is to pass those variables to the openSubtab
method.
var openSubtab = function (result, inputUrl, inputTitle) {
// logic
}
However, you don't even need to make each call asynchronous. You can perform the asynchronous logic on page load.
(function (D, c) {
var primaryTabId; // locally scope your variable
D.addEventListener('DOMContentLoaded', function() {
c.getEnclosingPrimaryTabId(function (tab) {
primaryTabId = tab.id;
});
});
})(document, sforce.console);
Now you can remove that first line (and parameter) from openSubTab
and make these calls synchronously on click.
So back to your loop. You are trying to pass a url of caseId
, but that is not even a valid url. Make sure you prepend a /
character to make it a relative path. I would recommend using the $Action
variable but that might be overly complicated in this script. Since eventually you will be iterating a List<Case>
, I recommend designing your function to simply accept a Case
record. Something like:
(function (D, c) {
var baseUrl = "{!LEFT($CurrentPage.URL,FIND('/',$CurrentPage.URL,9))}",
openTab = function (caseRecord) {
var caseUrl = baseUrl + caseRecord.Id,
caseTitle = caseRecord.CaseNumber;
if (!c.isInConsole) {
window.open(caseUrl, "_blank");
window.focus();
}
else {
c.openSubTab(primaryTabId, caseUrl /*other parameters*/);
}
}
// include here DOMContentLoaded listener outlined above
})(document, sforce.console);
Best Answer
Thanks All!!
Below formula is working for me