7

In communities, I have embedded a lightning components that edits the record in another form component and on save it redirects back to detail layout.

The problem I am facing is after update when it redirects, I can see old values, while when i Query/refresh page i can find new values.

Code used for redirection.

             var urlEvent = $A.get("e.force:navigateToSObject");
            urlEvent.setParams({
                "recordId": oppId,
                "slideDevName" :'related'
            });
            $A.get('e.force:refreshView').fire();/** Added as per suggestion **/
            urlEvent.fire();

Somewhere in between Lightning container is showing me old values. Can someone give me some pointers on this issue?

7
  • So I think you had declared a attribute from which records are updated. So just before redirecting fire an event and update that attribute with updated values... Jan 29, 2017 at 13:55
  • I update record in APEX. Redirect to standard detail view of record. Why should i update value of an attribute if am redirecting to detail page. Jan 29, 2017 at 13:58
  • You are redirecting to lightning component? If yes, then either in init you meet to update attribute or refresh using events.. Jan 29, 2017 at 14:01
  • Am not redirecting to a custom lighting component. e.force:navigateToSObject is standard lightning compoent provided by salesforce, whose init method is not public to override Jan 29, 2017 at 14:02
  • 1
    This might be an issue in their underlying data cache in Lightning. I sometimes see this when in Lightning Experience. We have a custom VF edit page for an object and about 50% of the time after editing the record on that page and saving, the record detail in lightning is still showing the old data. Note that we are using all standard mechanisms here (ApexPages.StandardController in VF and the basic Lightning Experience record page). Hopefully they fix this soon since waiting 10 to 15 seconds for a page refresh after editing really sucks.
    – dsharrison
    Feb 3, 2017 at 0:02

3 Answers 3

4
+25

$A.get('e.force:refreshView').fire(); This event or this code you are using in one.app that's why this is not working.

It’s supported in Lightning Experience and Salesforce1 only.

Refer it

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_force_refreshView.htm

5
  • 1
    one.app IS the lightning experience and salesforce1. Feb 2, 2017 at 10:17
  • I am using $A.get('e.force:refreshView').fire(); in lightning component in community and it is working fine. Feb 3, 2017 at 8:49
  • @JaiChaturvedi are you redirecting to detail page after that? Problem is in detail page which is showing the old values. Feb 3, 2017 at 13:23
  • No, I am not redirecting it to anywhere. Just refreshing after successful callback from server class. It just refreshes the section to include the latest inserted record in the list. Feb 4, 2017 at 7:51
  • When you redirect to detail page, this doesn't work. Feb 5, 2017 at 3:21
3

The lightning container is still buggy. As i am redirecting to detail page, I started using Javascript window methods rather e.force:navigateToSObject methods.

window.location ='/myportal/s/opportunity/'+oppId ;

redirects to opportunity and via hard page reload thus loading new values from database.

I know its not recommended by salesforce, but had no other option. Hope salesforce fixes this soon.

4
  • This does not work properly, when a standard button like edit is overriden with visualforce using lightning out, Salesforce is opened inside the page view and we see home tabs twice.
    – Raul
    Sep 28, 2017 at 13:05
  • My question was specific to communities and was pure lightning, Lightning out was beta then. The given answer worked for me. I had raised bounty too, no solution worked then. Sep 28, 2017 at 14:29
  • Ah gotcha, but same behavior if I use a component to override a standard action. I guess your scenario was completely different.
    – Raul
    Sep 28, 2017 at 14:31
  • Thanks mate :) Not all pain has same remedy :) cheers Sep 28, 2017 at 15:03
0

As of today you are able to trigger a refresh without reloading the page or using a gimmick. You should use the RefreshView API:

import { LightningElement } from "lwc";
import { RefreshEvent } from "lightning/refresh";

export default class RefreshButton extends LightningElement {
  // signal a refresh programmatically
  // or via a button click
  beginRefresh() {
    this.dispatchEvent(new RefreshEvent());
  }
}

You must log in to answer this question.

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