0

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?

2
  • is your method cached ? have you looked into using refreshApex?
    – glls
    Commented Jan 21, 2022 at 18:18
  • Yes. It has annotation, I'm using refresh method too. But the problem is when I click on component inside aura, this action doesn't update the LWC. Commented Jan 21, 2022 at 23:21

1 Answer 1

0

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);
    }
}

You must log in to answer this question.

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