LWC changes updates Aura, BUT Aura changes does not updates LWC

auralightning-message-channellightning-web-components

I have a scenario where two components an Aura and a LWC were included via Object Record Type. They are placed according to the image below.

enter image description here

I'm facing a problem. All the interactions done in LWC gets the related data in Aura updated. But, when some data in aura are updated, the related data in LWC are not update. That is, LWC does not know it. It is not refreshed. It is done only when I refresh the entire page so that an @wire function (methodController) is called. See below.

import methodController from '@salesforce/apex/Controller.methodController';

    @wire(methodController, { 
        recordId: '$recordId' 
    })
    handle({error, data}) 
    {
      // business logic
    }  

methodController is called only once, when the page is loaded.

How to make it to be called all the time that some actions in Aura are done?

Best Answer

I have found the solution.

It is in this post. This design worked in the scenario that I have posted

https://developer.salesforce.com/forums/?id=9062I000000DOUnQAO

import { LightningElement, api, wire } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { getRecord } from 'lightning/uiRecordApi';
const FIELDS=['Account.Id'];

export default class ShowToast extends LightningElement {
    @api recordId;
    account;
    lastModifiedDate;
    
    @wire(getRecord, { recordId: '$recordId', fields: FIELDS })
    wiredRecord({ error, data }) {
        if (error) {
           console.log('error occured');
        } else if (data) {
            this.account = data;
            let modifiedDate = this.account.lastModifiedDate;
            if(!this.lastModifiedDate) {
                this.lastModifiedDate = this.account.lastModifiedDate;
            }
            if (modifiedDate != this.lastModifiedDate) {
                this.showNotification();
            }
        }
    }

    showNotification() {
        const evt = new ShowToastEvent({
            title: 'Success',
            message: 'Account Updated',
            variant: 'success'
        });
        this.dispatchEvent(evt);
    }
}
Related Topic