2

Whenever changes happened in child record i want to update a field in my Parent.Parent field should be updated without refreshing the UI. So i have created a trigger in my child ,updated my parent field and captured the parent id. For each parent id I have subscribed my platform event below.

    List<Account> lstAccount = new List<Account>();
    List<Platformrefresh__e> eveList =new List<Platformrefresh__e>();
    for (Contact con : lstContact){
        //my logic to update account field
        lstAccount.add(acc);
        Platformrefresh__e event = new Platformrefresh__e();
        event.recordId__c= con.AccountId
        eveList.add(event);
    }
    update lstAccount;
    EventBus.publish(eveList);

I have created LWC component and added in my Parent record lightning page. Whenever the change happened in parent i am displaying some message like below

handleResponse(response) {
    console.log('entering response'+JSON.stringify(response));
    let parentRecord = response?.data?.payload?.recordId__c;
    if (parentRecord === this.recordId) {
        console.log('entering refresh');
        getRecordNotifyChange([{ recordId: this.recordId }]);
        this.dispatchEvent(
            new ShowToastEvent({
                title: 'Success',
                message: 'Account updated',
                variant: 'success'
            })
        );
        //Unsubscribe immediately after single refresh.  
        //Makes sure that we're not oversubscribed as disconnectedCallback does not seem consistent.
        //this.unsubscribeToMessageChannel();
    }
}

I am getting the message but the value in the UI is not refreshed all the time. Sometimes the UI gets refreshed and sometimes not. Can anyone please help me.Thanks in advance.

1 Answer 1

0

You need to try putting getRecordNotifyChange after dispatchEvent, it works for me

You must log in to answer this question.

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