3

I tried to use an application event in visualforce page using lighting out on my scratch org with namespace. But I was not able to get the app event in aura component.

I wrote following Aura Component, Aura Application Event, Aura Application for Lighting Out, and Visualforce Page.

Even if displaying myPage.page and clicking "Get event" button on myComp.cmp, but unable to get event in myAction method of myCompController.js.

I tried to replace mynamespace to c, but the result was same.

In scratch org without namespace and developer org with namespace, I could get the application event with same code.

So this problem seems to be bug of scratch org with namespace. Please fix this problem.

myAppEvent.evt

<aura:event type="APPLICATION" description="My App Event template"/>

myComp.cmp

<aura:component implements="flexipage:availableForAllPageTypes">
    <aura:registerEvent name="appEvent" type="mynamespace:myAppEvent"/>
    <div>
        <div><button onclick="{!c.myAction}">Get event</button></div>
    </div>
</aura:component>

myCompApp.app

<aura:application extends="ltng:outApp">
    <aura:dependency resource="c:myComp" />
</aura:application> 

myPage.page

<apex:page>
    <apex:includeLightning />
    <div id="lightning"></div>
    <script>
        $Lightning.use("c:myCompApp", function () {
            $Lightning.createComponent("c:myComp", {}
                , "lightning", function (cmp, err) {});
        });
    </script>
</apex:page>

myCompController.js

({
    myAction : function(component, event, helper) {
        var event = $A.get('e.mynamespace:myAppEvent');
        console.log("evenet: ", event);
    }
})

sfdx-project.jon

{
  {
  "packageDirectories": [
    {
      "path": "force-app",
      "default": true
    }
  ],
  "namespace": "mynamespace",
  "sfdcLoginUrl": "https://login.salesforce.com",
  "sourceApiVersion": "47.0"
}

Your Answer

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

Browse other questions tagged or ask your own question.