Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Imperative Apex While Offline
Imperative Apex calls always fail when the client device is offline. When using
imperative Apex in an offline-enabled mobile app, it’s essential to handle the possibility of a
network failure error.
Treat errors as a normal, expected outcome, rather than a failure condition. Provide appropriate feedback to the user, and suggest alternative behavior, rather than treating the situation as unexpected.
1// apexImperativeMethod.js
2import { LightningElement, track } from 'lwc';
3import getContactList from '@salesforce/apex/ContactController.getContactList';
4
5export default class ApexImperativeMethod extends LightningElement {
6 @track contacts;
7 @track error;
8
9 handleLoad() {
10 getContactList()
11 .then(result => {
12 this.contacts = result;
13 })
14 .catch(error => {
15 this.error = error;
16 });
17 }
18}Offline-savvy components expect to be offline at times, and know what to do when that happens.