function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Bertrand DBBertrand DB 

Refresh record page after adding a related record in lightning

Hello,

Using lightning, I noticed that on Opportunity, if I add some products (OpportunityLineItems), the page will automatically refresh just after.
It is very convenient, because it permits to see the updated Amount field.

In my case, I'm not using OpportunityLineItems but I created a custom object for this need "Custom Line Item".
I have a related list on opportunity, where I can add/delete these items. When I do so, it triggers some Apex and update a field on my opportunity.

My issue is that I need to manually refresh the page to see that the field on opportunity was updated.

I would like to achieve:
  • On my opportunity, I add/edit a "Custom Line Item" directly from the related list
  • A popup opens, I add/edit the line
  • I save, and I'm back to the opportunity page
  • I need to refresh the page to see that the field is well updated by the Trigger. -> How to automatically refresh the page after I add/edit a "Custom line item" from the opportunity page?
Any suggestions?
Best Answer chosen by Bertrand DB
sfdcMonkey.comsfdcMonkey.com
hi Bertrand, No, with trigger you can't automatically refresh your detail page, you have need to refresh it manually, OR the other convenient way from user perspective is creating a Lightning Action button for record detail page with custom lightning component, and use following component code to refresh your page.

Lightning component :
<aura:component implements="force:lightningQuickAction">
   <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>  
    refreshing.....
</aura:component>
javaScript :
({
 doInit : function(component,event,helper){
   $A.get('e.force:refreshView').fire();
 },
 
})
ref : http://sfdcmonkey.com/2017/04/16/add-lightning-component-lightning-action/

Thanks, Kindly let us know if it helps you, & close this query by selecting best answer if you got your solution,so this will helps other in future
 
sfdcMonkey.com

All Answers

sfdcMonkey.comsfdcMonkey.com
hi Bertrand, No, with trigger you can't automatically refresh your detail page, you have need to refresh it manually, OR the other convenient way from user perspective is creating a Lightning Action button for record detail page with custom lightning component, and use following component code to refresh your page.

Lightning component :
<aura:component implements="force:lightningQuickAction">
   <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>  
    refreshing.....
</aura:component>
javaScript :
({
 doInit : function(component,event,helper){
   $A.get('e.force:refreshView').fire();
 },
 
})
ref : http://sfdcmonkey.com/2017/04/16/add-lightning-component-lightning-action/

Thanks, Kindly let us know if it helps you, & close this query by selecting best answer if you got your solution,so this will helps other in future
 
sfdcMonkey.com
This was selected as the best answer
Bertrand DBBertrand DB
Hello,
Thank you for this suggestion, which actually makes sense. I'll try to implement that.
K P 38K P 38
Hello Bertrand

I am facing the similar issue. I have created a lightning Quick Action button  which I need to click manually to refresh the page. May I know the solution to autorfresh the related records? 

Thanks in advance. 
smriti sharan19smriti sharan19
To refresh a view, run $A.get('e.force:refreshView').fire();, which reloads data for standard components

save : function(component, event) {                
        var action = component.get("c.apexSave"); 
        action.setCallback(this, function(action) {                
           $A.get('e.force:refreshView').fire(); 
        }); 
        $A.enqueueAction(action); 
    }