5

After we update a record and navigate to a detail page, it still shows the old data.

Steps:

  • Overridden edit button of Account with a Lightning component.
  • Also used a Visualforce page with lightning out to host the component as an override, but still have same issue.

Note: Navigation issue is in 2 places:

  1. Lightning Component: Using e.force:navigateToSObject
  2. Visualforce using lightning out: sforce.one.navigateToSObject

It looks like there is some caching issue after redirect.


To resolve this, I also turned off the cache as mentioned in this question, it didn't help: Lightning Experience: How to prevent the display of obsolete data?

Question is similar to Values are not updated in Lightning after record update but it does not have a proper answer.

I also know there is a known issue: Data updates are not reflected in UI after a Visualforce+Apex update in Lightning Experience. My scenario is different as it has a lightning component.

Please let me know if anyone else is facing similar issue; as this is most common use case to use a Lightning component or Visualforce for overriding standard button's action.

My code is pretty basic to just show the existing Account name with save button, can provide if required.


What I tried for navigation:

Iteration 1:

var navigationSObject = $A.get("e.force:navigateToSObject");
navigationSObject.setParams({
    "recordId": component.get("v.recordId")
});
navigationSObject.fire();

And using sforce.one.navigateToSObject when a VF page is used using Lightning out.


Iteration 2 (as per question: Values are not updated in Lightning after record update):

var navigationSObject = $A.get("e.force:navigateToSObject");
navigationSObject.setParams({
    "recordId": component.get("v.recordId")
});
$A.get('e.force:refreshView').fire();
navigationSObject.fire();
9
  • Hi @RahulSharma ! I think that's related to a bug already known by Salesforce. I'll try to find where I already saw this. Sep 28 '17 at 13:59
  • Hi @MartinLezer, I had posted the bug link in answer as well but I guess it is only happens when we use VF + apex? - Data updates are not reflected in UI after a Visualforce+Apex update in Lightning Experience. This is a major and annoying issue, not sure how others handle it. Do you know of any workaround?
    – Raul
    Sep 28 '17 at 14:03
  • Oh yes you're right that was the link I already saw. I don't know any workaround. Maybe you should try to create a custom lightning component which refresh the view at init. With none ui. And add this lightning component to the record page. The problem is that it will refresh the view each time the record is shown. Sep 28 '17 at 14:06
  • Can you try setting the param isredirect Ref: developer.salesforce.com/docs/atlas.en-us.lightning.meta/… Sep 28 '17 at 14:16
  • @HemantJain, isredirect` didn't help.
    – Raul
    Sep 28 '17 at 14:19
6

Used window.location as mentioned in the comments which opens the salesforce app inside child container/page.

Finally ended up using window.parent.location as below (instead of using $A.get("e.force:navigateToSObject") or sforce.one.navigateToSObject for Lightning component or VF page respectively.) -

window.parent.location = '/' + recordId;

Not sure if this is completely supported by Lightning but works for now.


Added:

  1. Tested and this works in Lightning UI when standard button is overridden:

    • Directly with Lightning component
    • Indirectly via Visualforce using Lightning out
    • When component is used in app builder.
  2. I have disabled toast message, showing a success message via toast is weird as message appears following by redirection.

6
  • 2
    Does it work also with: window.parent.location = '/one/one.app#/sObject/' + recordId + '/view' ? Sep 28 '17 at 15:04
  • It works and is much better from user perspective. because with just '/' + recordId, it first navigates to /one/one.app#/alohaRedirect/{ID} followed by the detail page URL which you have mentioned. Do you know the trick to generate that URL dynamically?
    – Raul
    Sep 28 '17 at 15:10
  • Unfortunately no :( I don't think this is possible. Or I am missing something. Sep 28 '17 at 15:12
  • It does not matter, using the URL which you specified is much cleaner for redirection!
    – Raul
    Sep 28 '17 at 15:15
  • Sorry @MartinLezer, the mentioned link didn't work. tested it properly now.
    – Raul
    Sep 28 '17 at 15:33
2

I found other workaround without redirection.

Adding an empty Lightning component for the affected layout:

Component code:

<aura:component implements="flexipage:availableForAllPageTypes"  access="global">
    <aura:handler name="init" value="{!this}" action="{!c.handleInit}"/>
</aura:component>

Controller code:

({
    handleInit : function(component, event, helper) {
        setTimeout(function(){ 
            $A.get('e.force:refreshView').fire();
        }, 1);


    }
})

In this case when you use "e.force:navigateToSObject" the layout is refreshed.

1

I have experienced a similar situation with an Aura component and Lightning Data Service. The issue was that we use a custom Apex controller to save the record. Lightning Data Service does not get notice about the change in database. It is not meant to be used that way, I think. One should use Lightning Data service to save the record.

However, I found a solution here: https://salesforce.stackexchange.com/a/249233/76507

Call reloadData(true) on your Lightning Record Service component to reload the record from the server.

    saveRecord: function(component, event, helper) {
        // call Apex controller
        var action = component.get("c.saveRecord");
        action.setParams({
            recordId: component.get("v.recordId"),
            recordFields: JSON.stringify(fields)
        });
        action.setCallback(this, function(response) {
            if(response.getState() === "SUCCESS"){
                // tell Lightning data service to reload record from server
                component.find("recordLoader").reloadRecord(true);
                // navigate to record page
                helper.navToRecord(component, response.getReturnValue().recordId);               

            } else {
                helper.handleError(component, response);
            }
        });
        $A.enqueueAction(action);
    },

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.