0

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:

enter image description here

The button click:

enter image description here

After the button click, the record still shows the old value:

enter image description here

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: enter image description here

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?

3 Answers 3

1

After some back-and-forth troubleshooting with Salesforce Support we identified the problem. My scratch org was defaulting to German and Google Chrome was performing the translation to English. This Chrome action was actually interfering with the Salesforce Lightning UI refresh. Disabling Chrome translation solved the issue.

0

Your code seems very alright and syntactically correct but I think maybe you should change the const keyword to let. You have defined the fields variable as a constant and most likely data that you are changing will not get written to it.

1
  • Unfortunately, that doesn't seem to have worked.
    – Paugh
    Commented Sep 20, 2022 at 11:32
0

You can also use the callback function so that everytime on the modification/Action on the record it does call the calls function.

1
  • This didn't work either. In my case it was a strange scenario of my scratch org being in a different default language and the process not firing when Chrome was translating the page. I worked with Salesforce support on this and no process (connectedCallback, renderedCallback, getNotificationofRecordChange(), etc.) worked. Telling Chrome not to translate the page eliminated the interference, and the component worked perfectly with my original code after that. As my primary org is not functioning this way, this issue only occurred in the scratch org.
    – Paugh
    Commented Oct 13, 2022 at 12:57

You must log in to answer this question.

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