0

I have a LWC Component added on Case object. Purpose of the component is to Change Ownership of the records and updates other fields on Case object. Once Ownership is changed, I have trigger which automatically creates Case Comments records. So for each ownership change, new Case Comment Records gets created.

Problem: When I navigate from LWC to Case record Page, with getRecordNotifyChange() I can see updated values in Case fields but I could not see updated count of Case Comment records in Case Comments Related objects (Looks like only Case Records get refreshed not their Related Child Records). In order to see latest Count of Case Comment, I have to navigate to Case Comments or refresh the screen.

Below is the sample Code:

    handleSave(event) {
    this.template.querySelectorAll('lightning-input-field').forEach(element => {
        element.reportValidity();
    });
    changeOwnership({
            userId: this.userId
        })
        .then(result => {
            if (result === 'Success') {
                // To refresh the page
                getRecordNotifyChange([{
                    recordId: this.casesId
                }]);
                this[NavigationMixin.Navigate]({
                    type: 'standard__recordPage',
                    attributes: {
                        recordId: this.casesId,
                        objectApiName: 'Case',
                        actionName: 'view'
                    }
                });

                
            } else if (result === 'Error') {

            }

        })
        .catch(error => {});
}

Can someone please help?

1 Answer 1

1

Though getRecordNotifyChange() should update the cache but you can also try setting a timeout using old way to refresh the related components. Try with both settimeout and without. You can also try putting this in promise received from navigation.

setTimeout(() => {
   eval("$A.get('e.force:refreshView').fire();");
}, 3000);    
3
  • Hi, I am using LWC not aura
    – SFDCDJ
    Feb 22, 2021 at 5:12
  • You can still use it in JS Feb 22, 2021 at 14:36
  • I tried by setting with timeout and it works as expected. thank you so much for the help!
    – SFDCDJ
    Feb 23, 2021 at 11:23

You must log in to answer this question.

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