I have implemented the custom datatable component(the child component c-custom-table not shown in this post) that is dispatching the event once the record have been successfully saved.
parentComponent.html
<template>
<div class="slds-p-var-around_medium">
<lightning-card title="Some Title">
<template if:true={someData.data}>
<c-custom-table some-data={someData.data}
onrecordupdate={handleSuccess}>
</c-custom-table>
</template>
</lightning-card>
</div>
</template>
The component is placed in the parent component that is handling the data fetching/ manipulation and passes it down to child components
parentComponent.js
import { LightningElement, api, wire } from "lwc";
import getSomeData from "c/someSobjectModule";
import { refreshApex } from "@salesforce/apex";
export default class ParentComponent extends LightningElement {
@api recordId;
@wire(getSomeData, { id: "$recordId" })
someData;
handleSuccess(event) {
return refreshApex(this.someData);
}
}
The problem is that the apex method is imported in a ES6 module that is handling other imports related to specific Sobject for code maintainability and also as a middle layer between front-end and back-end code.
someSobjectModule.js
import _getData from "@salesforce/apex/ApexController.getData";
const getData = (someId) => {
return _getData({ id: someId });
};
export { getData };
The apex method is flagged as cacheable once it's only fetching the data
ApexController.cls
public with sharing class ApexController {
@AuraEnabled(cacheable=true)
public static List<CustomObject__c> getData(String id){
List<CustomObject__c> data = new List<CustomObject__c>();
try {
data = [
SELECT Name, Quantity
FROM CustomObject__c
WHERE RelatedObjectId__c =: id ];
} catch (Exception e) {
throw new AuraHandledException(e.getMessage());
}
return data;
}
}
It seems that the wire service is not provisioning the data from apex due to inappropriate form as I am receiving the following error once I am trying to access a parent component
Message: adapter is not a constructor
Component Descriptor: c:parentComponent
If I call the apex method imperatively it behaves the same. On the other hand, if I import the apex method directly in parent component it works as expected. Is it possible to wire a method from ES6 module in parentComponent and then use refreshApex to reload the data? Am I forced exporting the apex method directly in the parent component by some framework vulnerabilities?