2

I built a lightning component to be used in a Visualforce page using Lightning Out, which works fine in my development environment, which is in Spring '18. However, when I pushed it to another environment, this one on the Summer '18 preview, I ran into an issue with my event handler override. The following code works on Spring '18 but only on Summer '18 when in debug mode.

If the user does not have access to the Apex controller, I get an error: This page has an error. You might just need to refresh it. Action failed: c:MyComponent$controller$navigateToOpportunity [Cannot read property 'recordId' of undefined] Failing descriptor: {c:MyComponent$controller$navigateToOpportunity}. Then if I give the user access, the page fails silently.

This follows the pattern from this previous question, and as I said, it works as expected both in Summer '18 debug mode and in Spring '18. Any idea of what exactly is going wrong? And any ideas for workarounds (other than enable debug mode for everyone) if this isn't resolved before Summer '18 is released?

Note: the Visualforce page is only meant to be used in SF Classic, hence only the window.location.href.

VF Page:

<apex:page id="MyPage">
    <apex:includeLightning />
    <apex:pageMessages />
    <div id="manager" style="width"></div>
    <script>
        $Lightning.use("C:MyDependency", function () {
            $Lightning.createComponent(
                "c:MyComponent"
                , {
                    recordId: "{!$CurrentPage.parameters.opportunityId}"
                    , standalone: true
                }
                , "manager"
                , function (component) {
                    $A.eventService.addHandler({
                        event: "force:navigateToSObject",
                        handler: function(event) {
                            window.location.href = "/" + event.$params$.recordId;
                        }
                    });
                }
             );
        });
     </script>
</apex:page>

Relevant code from controller:

navigateToOpportunity: function(component, event, helper){
    var navigationEvent = $A.get("e.force:navigateToSObject");
    navigationEvent.setParams({
        "recordId": component.get("v.recordId"),
    });
    navigationEvent.fire();
}

Button from component:

<lightning:button variant="neutral"
    label="Return to Opportunity"
    onclick="{!c.navigateToOpportunity}"
    iconName="utility:back"
    class="slds-m-around_small slds-float_left"/>

Dependency app:

<aura:application description="MyDependency" extends="ltng:outApp">
    <aura:dependency resource="c:MyComponent"/>
    <aura:dependency resource="markup://force:*" type="EVENT"/>
</aura:application>
  • 1
    Salesforce lightning team... please don't break this as it's hard enough to get nav working in lightning out. – Caspar Harmer May 22 '18 at 23:23
  • 1
    I wonder if you are running into issues with the line event.$param$.recordId - you could just try event.getParam('recordId') perhaps they don't like your method of accessing the param. – Caspar Harmer May 22 '18 at 23:29
  • 1
    That worked! Man, I hate how there are always multiple ways to do the same thing in lightning, and then one breaks in a new release... – SFDC Neuf May 22 '18 at 23:48
3

I wonder if you are running into issues with the line event.$param$.recordId

Try using event.getParam('recordId'). Perhaps the way you access the parameter is no longer supported.

| improve this answer | |
  • Huh. Where did that $param$ syntax come from anyway?? – Charles T May 23 '18 at 2:47
  • I've seen it a couple of times. I don't think we'll be seeing it again ;) – Caspar Harmer May 23 '18 at 3:22

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.