1

quick TLDR on what I'm building:

  • This is a standalone app that queries a list of accounts with incorrect hierarchy data, wires them into a function that does some formatting and pruning, and ultimately ends up with a variable called "accounts" that I display as a data table.

  • A button in one of the columns updates the parent account for a particular row, which would make it fall off the report, so I am trying to refresh the table after that happens to no longer show that row.

  • I want to make it so after a modal showing success pops up, the table is refreshed, but this is not working.

In this example hitting "Fix Hierarchy" calls an imperative function that does a DML update and then we should see that row no longer in the table. (I confirmed it works when I fully refresh the page).

enter image description here

Here is the initial code to fetch and wire the table:

accounts; 
@wire (getHierarchyMismatchAccounts)
createAccountTable({error, data}){

    if(data){
        let flattenedData = [];

        data.forEach(element => {
            let row = {};
            //omitted a bunch of formatting here to 
            //make the table look the way I want...
            flattenedData.push(row);
        });
        this.accounts = flattenedData;

};
}

Then, here is the onClick function that gets called that updates that account, and calls the refresh, but this doesn't seem to do anything and the table looks the same after even though I can confirm the data was updated.

updateHierarchy(){
    this.isLoading = true;
    updateHrchy({accID : this.currentAccID, newGlobalKey : this.currentParentHierarchyKey})
    .then((result) => {
        this.showSuccess = true;
        this.showModal = false;
        this.isLoading = false;
        return refreshApex(this.accounts)

    })
    .catch((error) => {
        this.errorMsg = error;
    })


}

Am I not passing the right thing to refreshApex? Since I go through a whole function of work before I set some new array to "this.accounts", do I need to handle this differently? To reiterate, when I refresh the entire page I don't see that row anymore so the backend logic/query is fine, its just not refreshing the wire service in the same session.

Thank you

3
  • Summary: the parameter to the wire handler has three properties. It's that third property that we never use directly that is used by refreshApex. See the linked Q&A for more info. If you still need help, please let us know, we'll be happy to reopen your question with additional information.
    – sfdcfox
    Aug 14, 2023 at 18:05
  • Hi, I am not sure I understand your proposed solution. I looked at the linked issue and I see that I am handling this the same exact way but mine is still not working. I have a class property (accounts) and you can see at the end of my wire function I set it using "this.accounts = flattenedData;". Elsewhere in the code I am doing " return refreshApex(this.accounts)", but this still didn't fix anything. This mirrors what I see in the other linked solution. They update a class variable in the wire function and then they return a refresh to that variable later. This didn't work for me.
    – Chris
    Aug 16, 2023 at 18:27
  • Instead of createAccountTable({error, data}) you need to use createAccountTable(result). That result property is what you need to save, e.g.. this.accountWiredResult = result, which you then use as refreshApex(this.accountWiredResult).
    – sfdcfox
    Aug 16, 2023 at 19:12

0

Browse other questions tagged .