Wire Adapters

By in
438
Wire Adapters

Use @wire to define the getRecord Lightning Data Service wire adapter to gain access to raw record data so that you may apply business logic or design a form that requires more customization than the LDS base components permit.

Use getListUi to show a list of field values, such as a list of contact names.

Although you can furnish data for numerous records using different wire adapters, each operation is a separate transaction. Use Apex to manage numerous records in a single transaction.

Call the createRecord, updateRecord, and deleteRecord functions in the lightning/ui*Api module to add, change, or remove a single record. Similar to the Lightning Data Service wire adapters, you can use numerous functions to operate with multiple records, but each operation is a separate transaction. Use Apex to manage numerous records in a single transaction.

Use the wire adapter that returns the least amount of data necessary for your use case to improve performance.

 

Use Apex

Use Apex if you are unable to use a base component or any Lightning Data Service wire adapters or functions.

Apex data is not handled like Lightning Data Service data; you must refresh the data. Call refreshApex(), which uses the wire configuration to obtain data and update the cache, if Apex data was provisioned via the wire service. If your code uses the getRecordNotifyChange() function to update the cache after calling an Apex method imperatively, the data will be refreshed.

Refreshing data from non-Apex wire adapters using refreshApex is no longer recommended. Use getRecordNotifyChange to update the record data returned by a non-Apex wire adaptor.

 

Lightning Data Services wire adapter for record info
Image Source: Developers.Salesforce

 

Conclusion

In this way, we should use LDS wherever possible except for the below conditions.

In these situations, use Apex:

  1. To work with objects like Task and Event that User Interface API does not provide.
  2. To perform tasks that the User Interface API is unable to perform, such as loading a list of records based on a set of criteria (for instance, loading the first 200 Accounts with an Amount > $1M).

 

To learn more about Lightning Web Components, check out some of my related blogs below!

 

Additional Resources

Cover Photo by Ryutaro Uozumi on Unsplash

Leave a reply

Your email address will not be published. Required fields are marked *