Summary: I'm trying to update the value of a record from a headless quick action button. The record updates successfully in the background, but the page never refreshes to reflect the updated value to the user. The idea is to get an activation code from an external source and update the record in Salesforce. For simplicity of the test I'm hard-coding the activation code value.
Here's the lwc code called from the quick action button:
import { LightningElement,api,wire } from 'lwc';
import { getRecord,updateRecord,getRecordNotifyChange } from 'lightning/uiRecordApi';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { refreshApex } from '@salesforce/apex';
import ID_FIELD from '@salesforce/schema/Instrument__c.Id';
import EMS_Activation_Code from '@salesforce/schema/Instrument__c.EMS_Activation_Code__c';
export default class EMS_Retrieve_Activation_Code extends LightningElement {
@api recordId;
@wire(getRecord, {
recordId: '$recordId',
fields: [EMS_Activation_Code]
})
instrument;
@api async invoke(){
const fields = {};
fields[ID_FIELD.fieldApiName] = this.recordId;
fields[EMS_Activation_Code.fieldApiName] = "Test 25";
const recordInput = { fields };
updateRecord(recordInput)
.then(() => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: 'Instrument updated',
variant: 'success'
})
);
})
.catch(error => {
this.dispatchEvent(
new ShowToastEvent({
title: 'Error creating record',
message: error.body.message,
variant: 'error'
})
);
});
}
}
Record prior to clicking the button:
The button click:
After the button click, the record still shows the old value:
How do I get the record detail page to refresh with the new activation code after the button click?
EDIT:
After logging data in the console I verified that the wired instrument data is in fact being updated and returned back to the lwc with the updated value and modification date:
Given that updateRecord(recordInput) is working correctly, the issue seems to be with the record detail page not being informed of this update. Is there some trick to forcing the record detail page to recognize a change and refresh the UI?