1

I have a lightning component on a record page that I want to refresh when the record is saved. How do I do this? Here is my Code:

Component:

<aura:component controller="DaytoBegin" implements="flexipage:availableForAllPageTypes,force:hasRecordId">

<aura:attribute name="ifmsrc" type="String"/>
<iframe id="frmprcrequest1" height="125px" src="{!v.ifmsrc}" frameborder="false" style="width:100%" />

Helper:

({
    buildComponents : function(cmp) {      
        var number = cmp.get("v.number");
        var oppid = cmp.get("v.recordId");
        $A.log(oppid);        
        cmp.set("v.ifmsrc", oppid);}    
}})

Renderer:

({
    render: function(cmp, helper) {        
        var ret = cmp.superRender(); 
        helper.buildComponents(cmp);
        return ret; 
    },

    rerender: function(cmp, helper) {
        helper.buildComponents(cmp);
    }
})

Controller.js:

({
    refresh : function(component, event, helper) {
        var action = cmp.get('c.AssignValue');        
        action.setCallback(cmp,
                           function(response) {
                               var state = response.getState();
                               if (state === 'SUCCESS') {
                                   $A.get('e.force:refreshView').fire();                                   
                               } else {
                                   console.log('Error')
                               }
                           });
        $A.enqueueAction(action);        
    }    
})

Added the refresh function and now I'm getting CMP not defined?

1

force:refreshView is used to refresh the view when you need to get new data. Something like this:

$A.get("e.force:refreshView").fire();
  • When I add that to my controller I get errors or it freezes during the refresh – AverageJoeVBA Jun 9 '17 at 17:08
  • This refreshes only the record page where the Component is hosted, you need to manually handle the refresh of your component – Simon Placentino Jun 13 '17 at 13:58
1

You need to check if you are in LEX or SF1 - which will handle handle the refreshView event for you and refresh the component.

If you are in lightning out, hosted by a VisualForce page for example, this event will return null, hence you get the component not defined error.

Try this:

var evt = $A.get('e.force:refreshView');
if (evt){
  evt.fire();
}
else {
  helper.buildComponents(); 
}

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.