1
  @wire(_getContacts,{recordId:'$recordId'}) wiredContacts({error,data}){
        this.dataToRefresh = data;
        if (data) {
            this.contacts = this.dataToRefresh.recordList;
            this.ContactsRecords = this.dataToRefresh.cList;           
            this.contactsSize = " Case Contacts (" + this.contacts.length + ")";           
        }else{
            //
        }
    };
relateContacts() {
        this.showSpinner = true;
        this.showtable=false;
        relateContacts({contacts: this.selected, recordId: this.recordId})
            .then(data => {
                this.showSpinner=false;
                this.showtable=true;
                this.showSuccessMessage(); 
                
                refreshApex(this.dataToRefresh);               
               
                //location.reload();
                this.isShowModal = false; 
            })
            .catch(error => {
                console.log(error);
                this.showSpinner=false;
                const evt = new ShowToastEvent({
                    title: 'Application Error',
                    message: error.body.message,
                    variant: 'error',
                    mode: 'sticky'
                });
                this.dispatchEvent(evt);
                this.showSpinner = false;
            });
    }

For this code, I tried refreshApex with all possible ways. but I'm not sure the miss here. I've Checked all the blogs but everywhere, the solution is mentioned.

Tried refreshApex like below :

@wire(_getContacts,{recordId:'$recordId'}) wiredContacts({data}){
        this.dataToRefresh = data;

But this also does not work
Keyvan Soleimani
  • 606
  • 2
  • 4
  • 16

1 Answers1

0

Ah that is a fun one ! Your issue is using destructuring in wiredContacts as the parameter. (The {data} or {data,error} normally works as a parameter to the function being called back, except if you have to do refresh)
Try this instead.

@wire(_getContacts,{recordId:'$recordId'}) wiredContacts(value){
        this.dataToRefresh = value;
        const {data, error} = value;
        //Rest of you code now with data and error 
         
}

Then in your other method you can do:

method(){    
          refreshApex(this.dataToRefresh);
 }

Salesforce does show doing this in their example code, but it’s easy to miss and experience the fun you have been having with this.
https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.apex_result_caching

See the last example on their page.

Falcon
  • 29
  • 5