Newer Version Available

This content describes an older version of this product. View Latest

Imperative Apex

Imperative Apex is the more traditional way to call an Apex method, as a network-based API call. Imperative Apex allows you to control exactly when the method is called. You’re in control of the invocation, rather than the framework.

Imperative Apex is more flexible—and less restrictive—than reactive Apex wires. For example, you can use imperative Apex calls to change data on the server. The full details are described in Call Apex Methods Imperatively in the Lightning Web Components Developer Guide.

However, imperative Apex has a significant limitation in an offline-enabled mobile app. You can’t use imperative Apex while offline. This is by design, since imperative Apex is allowed to change data on the server. There’s no way to reconcile what might change on the server side with data cached on the client side. This is because the client has no knowledge of the implementation of a server-side Apex method. See Imperative Apex While Offline.