1

I have a LWC included inside the Case Record Page. I need that when I edit an element (I mean, when I update a record) in the LWC Salesforce does refresh just for the isolated LWC and not all the Case Record Page.

For example, if I use window.location.reload() I get the refresh, but it impacts all the page and reload it. I want to reload the specific record and its view in the LWC without reloading all page.

I tried with refreshApex but it does not work. Any idea?

CODE:

JS:

invokeEditComment(){
        editCommentary({commentary: this.commentaryEdited, serviceId: this.serviceId, caseId: this.recordId})
        .then(() => {
            this.showNotify(this.title, 'Edited', 'success');
            this.showEditCommentModal = false;
            this.showSpinner = false;
            //Is in this point in which I want to make the refresh. ⬇️⬇️⬇️⬇️
            //return refreshApex(this.propuestaMetadata);
            //window.location.reload();

        })
        .catch(error => {
            this.error = error;
            this.showNotify(this.title, GEN_ADM_MSG_ERR, 'warning');
        });
    }

CONTROLLER APEX METHOD:

    @AuraEnabled
    public static void editCommentary(String commentary, String serviceId, String caseId)  {
        List<Services__c> serv = [SELECT Id,Comments__c, CaseId__c 
                                                   FROM Services__c
                                                   WHERE CaseId__c = :caseId];
        serv [0].Comments__c= commentary;
        update serv ;
    }

enter image description here

Blue zone is a Case Action that calls a flow, in which a screen contains the LWC. I want to refresh just the BLUE ZONE, and not all the page. Result must be like this:

enter image description here

18
  • Hi. You need to provide some detail here because it isn't clear what "edit an element" is and in what way refreshApex wasn't working. Add some code snippets and a clearer explanation of what you mean. Please edit to add this.
    – Phil W
    Commented Mar 2, 2022 at 11:27
  • I edited. I mean when I update a record. For example, I have a LWC inside the Case Record Page that gets Services__c CustomObject and let you edit them and update them. When I update, I want user sees the records edited without reloading all Case Record Page. If Services__c has a field Comments__c, and it's 'A' and user changes it to 'B', I want that user sees 'B' after editing just refreshing LWC that controls Services__c, without reloading all Case Record Page.
    – CPS
    Commented Mar 2, 2022 at 11:42
  • RefreshApex just does not work as implementing as I checked. I could put the code, but I wanted to know if there is another option.
    – CPS
    Commented Mar 2, 2022 at 11:44
  • The options entirely depend on a) what mechanism is used to update the record and b) how the LWC gets its data to show. This is why we need you to add detail. If your LWC uses the uiRecordApi then it should auto-refresh when the same record is modified elsewhere in the page, but I'm guessing you wrote your own apex method to get the data instead.
    – Phil W
    Commented Mar 2, 2022 at 11:51
  • Yes, is the second way, I wrote my own apex method. So, I put the code.
    – CPS
    Commented Mar 2, 2022 at 11:58

1 Answer 1

0

You are able to use the RefreshView API now. Import RefreshView from lightning/refresh and dispatch that event.

import { RefreshEvent } from "lightning/refresh";

export default class YourComponent extends LightningElement {
  method() {
    // this will tell the view to refresh its contents
    this.dispatchEvent(new RefreshEvent());
  }
}
1
  • 1
    I used the below as you suggested and its working for first time , but when I revisit the component/tab where the component is called for the second time its not updating with the latest values . any suggestion on it ? Thanks You are able to use the RefreshView API now. Import RefreshView from lightning/refresh and dispatch that event. import { RefreshEvent } from "lightning/refresh"; export default class YourComponent extends LightningElement { method() { // this will tell the view to refresh its contents this.dispatchEvent(new RefreshEvent()); } }
    – Archana
    Commented Feb 20 at 8:59

You must log in to answer this question.

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