2

I have a lightning component similar to:

<aura:component>
    <aura:handler name="myevent" action="{!c.myRerender}" />

    <lightning:recordViewForm recordId="{!v.recordId}" objectApiName="MyObj__c" />
</aura:component>

How can I get my <lightning:recordViewform> to reload? Usinge.force:refreshView` is not a viable answer as it reloads other things as well.

5
  • 1
    Did you try loading lightning:recordViewForm with a separate component using $A.createComponent ? Jan 14, 2019 at 19:41
  • Not a duplicate as this use case is different and not answered in that question.
    – dphil
    Jan 14, 2019 at 19:58
  • 1
    @dphil, including + code and what you have tried will likely reduce the chances of your posts being marked as duplicates.
    – glls
    Jan 14, 2019 at 22:24
  • @codeyinthecloud I have not. Maybe I'll try that next.
    – dphil
    Jan 15, 2019 at 14:45
  • For those that closed this, that linked question/answer does NOT answer this question/cover this scenario.
    – dphil
    Jan 16, 2019 at 19:51

1 Answer 1

1

Because the recordEditForm stores the object in the DOM it will not automatically update unless it is re-pulled from server. To do this just set the recordId attribute of the recordEditForm to null and then back to the correct record Id and it will grab the updated version of the record

AURA

<aura:attribute name="recordId" type="Id"/>
<aura:handler name="myevent" action="{!c.myRerender}" />
<lightning:recordViewForm recordId="{!v.recordId}" objectApiName="MyObj__c">

JS

myRerender : function(cmp, event, helper){
    var recId = cmp.get('v.recordId');
    cmp.set('v.recordId', null);
    cmp.set('v.recordId', recId);
}
10
  • Have you tested this solution? I had approached my co-workers with this exact same solution and they had said they already tried this and it did not work.
    – dphil
    Jan 14, 2019 at 20:03
  • I have used the handler on the refreshView event before and I know that changing an aura:if statements boolean value refreshed that part of the DOM Jan 14, 2019 at 20:05
  • Thanks, I'll try it myself and see if it works then.
    – dphil
    Jan 14, 2019 at 20:05
  • There is also the renderer.js aspect of lightning components which may be the preferred method of re-rendering the DOM but I've never gotten that to work right. developer.salesforce.com/docs/atlas.en-us.lightning.meta/… Jan 14, 2019 at 20:07
  • 1
    Your next idea worked. If you wanted to put it into an answer I can accept it.
    – dphil
    Jan 15, 2019 at 17:28

You must log in to answer this question.

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