Tuesday 7 September 2021

How to reload record page automatically from LWC component ?

 Use case - Sometime we may need to update record or create child record from a quick action. To see new value we have to refresh page automatically to avoid manual refresh by user.

Assume I have quick action on Lead, which create record in Child Object also create content documents. 

My quick action invoke lighting component to perform these action, now I have to refresh Lead page on successful completion. Here is code that will achieve.

1. We need to import library in JS file 

import { updateRecord from 'lightning/uiRecordApi';

2. @api recordId; this will capture lead record Id

3. Add a function in JS file

updateRecordView(recordId) {
       console.log('updateRecordView called ',this.recordId)
       updateRecord({fields: { Id: this.recordId }});
}

4. Finally call updateRecordView where you are generating sucess event 

this.showSuccess();
   console.log('lead id',this.recordId);
this.updateRecordView(this.recordId);


No comments: