When do you need to call APEX methods imperatively?
In the following scenarios, you must call an Apex method imperatively as opposed to using @wire. To call a method that isn’t annotated with cacheable=true, which includes any method that inserts, updates, or deletes data. To control when the invocation occurs. To work with objects that aren’t supported by User Interface API, like Task and Event.
Is the cacheable true for the APEX method?
If an Apex method is marked with @ AuraEnabled( cacheable =true), a client-side Lightning Data Service cache is checked before issuing the network call to invoke the Apex method on the server. However, Lightning Data Service doesn’t manage data provisioned by Apex.
How to pass parameters to the APEX method?
Pass parameters values to an Apex method in an object whose properties match the parameters of the Apex method. For example, if the Apex method takes a string parameter, don’t pass a string directly. Instead, pass an object that contains a property whose value is a string.
What happens when you call a method imperatively?
To control when the method invocation occurs (for example, in response to clicking a button), call the method imperatively. When you call a method imperatively, you receive only a single response. Compare this behavior with @wire, which delegates control to the framework and results in a stream of values being provisioned.
How to expose APEX method in Lightning component?
To expose an Apex method to a Lightning web component, the method must be static and either global or public. Annotate the method with @AuraEnabled. To read Salesforce data, Lightning web components use a reactive wire service. Use @wire in a component’s JavaScript class to specify an Apex method.
How to wire a component to the APEX method?
Important To @wire the component to the Apex method, the first parameter is a string, which is the name of the Apex method—in this case, findContacts. The second @wire parameter is an object that contains the parameters to pass to the Apex method.