Hot Posts

6/recent/ticker-posts

Wire Adapters & Functions in LWC

Introduction to apex programming

 

Understand the wire service

Import a wire adapter using named import syntax. Decorate a property or function with @wire and specify the wire adapter. Each wire adapter defines a data type.

The wire service provisions an immutable stream of data. The data is not guaranteed to be the same, even when the adapterConfig object content is the same.

wire service in LWC

Example of Wire with uiRecordApi

Import References 

Using wire adapters you can import references to Salesforce Objects and Fields. Salesforce verifies that the objects and fields exist, prevents objects and fields from being deleted, and cascades any renamed objects and fields into your component’s source code. It also ensures that dependent objects and fields are included in change sets and packages. Importing references to objects and fields ensures that your code works, even when object and field names change.

Import a reference to an object

field Import reference

Import reference to relationship field

Tip: For objects, we use the naming convention OBJECTNAME_OBJECT. For fields, we use the naming convention FIELDNAME_FIELD. We use these naming conventions to make code easier to understand. They’re guidelines, not rules.

Import field and use it in a wire adapter config object

Import field and use it in a wire adapter config object

Import References for Compound Fields

@Wire with Property

Wiring a property is useful when you want to consume the data or error as-is. If the property decorated with @wire is used as an attribute in the template and its value changes, the wire service provisions the data and triggers the component to rerender. The property is private, but reactive

@Wire with Property

Decorate a function with @wire

Wiring a function is useful to perform logic whenever new data is provided or when an error occurs. The wire service provisions the function an object with error and data properties, just like a wired property.

Decorate a function with @wire

Post a Comment

0 Comments