4

My Lightning component:

<aura:component controller="MyController" implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global">
    <aura:attribute name="recordId" type="Id"/>
    ...
    <button type="button" onclick="{!c.doRun}">Activate Next</button>
</aura:component>

which is embedded into a Standard Layout using Visualforce and Lightning Out

<apex:page standardController="CustomObject__c">
    <apex:includeLightning />

    <div id="mydiv" />

    <script>
    $Lightning.use("myApp", function() {
        $Lightning.createComponent("myComponent",
                                   { recordId : "{!CustomObject__c.Id}" },
                                   "mydiv",
                                   function(cmp) {});
    });
    </script>
</apex:page>

is unable to fire the standard app event $A.get("e.force:refreshView").fire()

({doRun : function(component, event, helper) {
    var action = component.get("c.run");

    action.setCallback(this, function(response) {
        if (component.isValid() && response.getState() === "SUCCESS") {
            $A.get("e.force:refreshView").fire();
        }
    });

    $A.enqueueAction(action);        
}})

When I click the button this error appears on the screen:

This page has an error. You might just need to refresh it. Error in $A.getCallback() [Cannot read property 'fire' of undefined] Failing descriptor:

DISCLAIMER: I know that this is a duplicate of $A.get('e.force:refreshView').fire() did not refresh the record detail component but this question got lost in irrelevant details and found no solution yet.*

1 Answer 1

3

The behaviour is documented here.For lightning out if you are outside the SF1 container or lightning experience ,then standard events will not work .

Update:

I understand that you are inside the lightning experience and in that case try registering the event

<aura:registerEvent name="refreshView" type="force:refreshView" />
9
  • But the user has Lightning active and is looking at a Lightning version of a records detail page (defined by a standard layout with an embedded VF page). How can I reload the current page instead? Oct 21, 2016 at 13:41
  • Ah I see .Ok let me update my answer . Oct 21, 2016 at 13:44
  • I had to use <aura:registerEvent name="refreshView" type="force:refreshView" /> and it indeed worked. But only the embedded page reloads not the whole visualforce page. Oct 21, 2016 at 14:16
  • So only detail page reloaded and not the VF page ? You can use callback and call a non-lightning code (wndow.reload()) using developer.salesforce.com/docs/atlas.en-us.lightning.meta/… Oct 21, 2016 at 14:20
  • When I do this i get a cross site error: Error in $A.getCallback() [Blocked a frame with origin "myns.na8.visual.force.com" from accessing a cross-origin Oct 21, 2016 at 14:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .