Agenda
- Understand the Wire Service
- Syntax
- Import reference to Objects and Fields
- Wire with Property
- Wire with Function
- Sample code snippet and examples
The wire service provisions an immutable stream of data to the component. Each value in the stream is a newer version of the previous value set.
We call the wire service reactive in part because it supports reactive variables, which are prefixed with $. If a reactive variable changes, the wire service provisions new data.
Now here you might be hearing few terms first time like immutable stream & reactive parameters.
Immutable data is a piece of information in a database that cannot be (or shouldn’t be) deleted or modified. Most traditional databases store data in a mutable format, meaning the database overwrites the older data when new data is available. For example, in an employee database, the address information is over-written when an employee changes their residence.
In contrast, the databases that store immutable data will not overwrite an old item when new information is available. They use various techniques to preserve the historical and current values of the data.
Reactive variables can trigger reactive changes in your application. Whenever you modify the value of a reactive variable, queries that depend on that variable refresh, and your application's UI updates accordingly.
Syntax
Import Reference
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.
Example: Import a reference to an object
Example: Import reference to a field
Example: Import reference to relationship field
Example: Import References for Compound Fields
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.
@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 Function
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.
0 Comments