-1

Apex Refresh is not working, Can any one please help me on this.

import { refreshApex } from "@salesforce/apex";

JS

@wire(getParentGuardian, { EnrollmentId: "E0008" })
enroll({ data, error }) {
this.wiredDataResultRefresh = data;
if (data) {
  let mapped = data.map(row => [
    {
      firstName: row.Father_First_Name__c,
      lastName: row.Father_Last_Name__c,
      email: row.Father_Email__c,
      cell: row.Father_Cell__c
    },
    {
      firstName: row.Mother_First_Name__c,
      lastName: row.Mother_Last_Name__c,
      email: row.Mother_Email__c,
      cell: row.Mother_Cell__c
    }
  ]);
  this.wiredDataResult = mapped.flat();      
} else if (error) {
  this.error = error;
  this.parameters = undefined;
}
}

refreshData() {
return refreshApex(enroll(this.wiredDataResult));
// return refreshApex(enroll);
}

Controller:

public with sharing  class GetParentGuardianController {

@AuraEnabled (cacheable = true)
public static List<Enrollment__c> getParentGuardian(String EnrollmentId) {      

    system.debug('ENROL ' + EnrollmentId);      

  return   [select  Id, Father_First_Name__c, Father_Last_Name__c, Father_Email__c, Father_Cell__c
                              ,Mother_First_Name__c ,Mother_Last_Name__c, Mother_Email__c, Mother_Cell__c
                              from Enrollment__c WHERE Name=:EnrollmentId];

     // return ls; 

}    
}
  • 1
    try using refreshApex(this.wiredDataResult); – User6670 Feb 28 at 6:20
5

This is a simple mistake of not using the entire response object, but instead trying to use just one of its properties.

Instead of:

@wire(getParentGuardian, { EnrollmentId: "E0008" })
enroll({ data, error }) {
    this.wiredDataResultRefresh = data;

    ...

You MUST do the following:

@wire(getParentGuardian, { EnrollmentId: "E0008" })
enroll(response) {
    this.wiredDataResultRefresh = response;
    const data = response.data;
    const error = response.error;

    ...

You'll then call the refresh using:

refreshApex(this.wiredDataResultRefresh);

Without providing the complete response obtained the Apex Refresh mechanism has no way to map back to the cache.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.