Is it possible to call a wire adapter such as getObjectInfo
imperatively? I know they return void
and not a Promise
so surely they can't be called like an Apex method. This is the error I've been getting:
LWC component's @wire target property or method threw an error during value provisioning. Original error:
[this.callback is not a function]]
Example call I've tried:
method() {
getObjectInfo({ objectApiName: 'Account' });
}
If this is not possible is there any way I could utilize the LDS adapters imperatively as opposed to resorting to Apex? In my case I want to retrieve a list of fields for an object, on demand.
Best Answer
No, wire methods cannot be called imperatively.
If you need to do some special handling afterwards, set this up in the wire handler:
To actually trigger the call, you can set a reactive variable:
If you wanted to further make the call dynamic, you can do that, too!