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
Ashwini ZineAshwini Zine 

when creating an adding products to opportunity in lightning, you have to refresh page for products to appear in related list

I have Embedded the Visualforce page on the Add Product button in lightning experience. when I am adding the product to opportunity, after adding I need to manually refresh the page again to appear the products in related list. Unless and until I manually refresh the page the products do not appear in related list in lightning. But same process of adding the products to opportunity carried in classic and the products get appeared in related list without refreshing the page.
Best Answer chosen by Ashwini Zine
Khan AnasKhan Anas (Salesforce Developers) 
Hi Ashwini,

Greetings to you!

Currently, there is a known issue in lightning that prevents reflection of data updates on UI.

https://success.salesforce.com/issues_view?id=a1p3A0000001C8QQAU&title=data-not-updated-in-ui-after-an-apex-update-in-lightning-experience

Workaround by Salesforce:

Updates made to Lightning Experience and Salesforce app components may occasionally not be reflected in the UI. Updates initiated by a different user or a different channel (API, Apex Trigger, etc) require an additional mechanism in order to update the UI. 

The recommended solution is to refactor the component to use Lightning Data Service (force:recordData). Lightning Data Service provides a performance increase and eliminates out-of-sync issues. If you can’t refactor your component to use Lightning Data Service, you can also use force:refreshView to request a page refresh.

It means you need to create a lightning component. Try like this:
clientMethod : function(component,event,helper) {
        var action = component.get("c.serverMethod");   //calling server-side method
        action.setParams({
        "serverParameter":clientParameter
    });
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === 'SUCCESS'){
                $A.get('e.force:refreshView').fire();
            }
            ...
            ...
            ...
        )};
        $A.enqueueAction(action);
},

/*page refresh after data save*/
    
    isRefreshed: function(component, event, helper) {
        location.reload();
    },

And don't forget to add below handler in your component:
<aura:handler event="force:refreshView" action="{!c.isRefreshed}" />

Also, please make sure to turn off browser caching in your Org.

1. From Setup, locate the link to ‘Session Settings’.
2. Locate the ‘Caching’ section.
3. Uncheck the option to ‘Enable secure and persistent browser caching to improve performance’.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi Ashwini,

Greetings to you!

Currently, there is a known issue in lightning that prevents reflection of data updates on UI.

https://success.salesforce.com/issues_view?id=a1p3A0000001C8QQAU&title=data-not-updated-in-ui-after-an-apex-update-in-lightning-experience

Workaround by Salesforce:

Updates made to Lightning Experience and Salesforce app components may occasionally not be reflected in the UI. Updates initiated by a different user or a different channel (API, Apex Trigger, etc) require an additional mechanism in order to update the UI. 

The recommended solution is to refactor the component to use Lightning Data Service (force:recordData). Lightning Data Service provides a performance increase and eliminates out-of-sync issues. If you can’t refactor your component to use Lightning Data Service, you can also use force:refreshView to request a page refresh.

It means you need to create a lightning component. Try like this:
clientMethod : function(component,event,helper) {
        var action = component.get("c.serverMethod");   //calling server-side method
        action.setParams({
        "serverParameter":clientParameter
    });
        action.setCallback(this, function(response){
            var state = response.getState();
            if(state === 'SUCCESS'){
                $A.get('e.force:refreshView').fire();
            }
            ...
            ...
            ...
        )};
        $A.enqueueAction(action);
},

/*page refresh after data save*/
    
    isRefreshed: function(component, event, helper) {
        location.reload();
    },

And don't forget to add below handler in your component:
<aura:handler event="force:refreshView" action="{!c.isRefreshed}" />

Also, please make sure to turn off browser caching in your Org.

1. From Setup, locate the link to ‘Session Settings’.
2. Locate the ‘Caching’ section.
3. Uncheck the option to ‘Enable secure and persistent browser caching to improve performance’.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Ashwini ZineAshwini Zine
Hi Khan Anas  ,

Thank you! the solution helped me.