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.*

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" />
  • 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? – Robert Sösemann Oct 21 '16 at 13:41
  • Ah I see .Ok let me update my answer . – Mohith Shrivastava Oct 21 '16 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. – Robert Sösemann Oct 21 '16 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/… – Mohith Shrivastava Oct 21 '16 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 – Robert Sösemann Oct 21 '16 at 14:38

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.