0

I am updating a record and want to show the updated value on the record page. I am looking to update the status field on the Case object.

My component is wrapped in a LC as it is called from a quick action (LC just passes the id to LWC and nothing more).

I am not sure if I need to return the case status to my js so I can update it with apex refresh Apex:

@AuraEnabled
public static void getStatusCase(ID caseID){
    Case c = [select id, Status from case where ID =: caseID];
    c.status = 'Closed';
    update c;

    Case updatedCase = [select id, Status from case where ID =: caseID];
    return updatedCase.Status;
}

Everything is imported but omitted. I am unsure if I need to import the status field itself. JS:

Status
connectedCallback() {
    // initialize component

    window.console.log("here in console");
    updateStatusCase({ caseID: this.recordId})
            .then(result => {
                if(result){
                    this.Status = result;
                    window.console.log("updated status: " + this.Status);
                }
                refreshApex(this.Status);
                //window.location.reload();
            })
            .catch(error => {
                window.console.log("error: " + JSON.stringify(error));
            });   
    }

I feel like there is a disconnect between the status field on the record page and the status field in my code.

5
  • The return type for getStatusCase should be string, not void. Also, I think updating records inside connected callback is a not good idea, it gets called every time component is refreshed. Jun 9, 2020 at 13:46
  • Ah thanks. Do you know of a way to update the status field without using window.location.reload
    – M guy
    Jun 9, 2020 at 13:53
  • Yes, I have updated the same in answer Jun 9, 2020 at 13:56
  • 1
    Thanks. I will do what you said
    – M guy
    Jun 9, 2020 at 14:01
  • please ignore the connectedcallback part of my first comment. I had jumbling between a connected and rendered call back., sorry for that. Jun 9, 2020 at 14:10

1 Answer 1

2

The return type for getStatusCase should be string, not void.

Also, as you are using the Aura component, you can fire one refreshView event from it. For that you need to fire one event from child LWC to parent Aura, then fire force:refreshView from aura handler.

In addition to the above, the following link describes how to communicate between Aura and LWC https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.events_sending_to_aura_components

You must log in to answer this question.

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