Work with Salesforce Data  --  Use Wire Adapter and Function in LWC

 


In this topic, we will get to know how wire adapter and function are work with salesforce data in LWC component.

To read Salesforce data, Lightning web components use a reactive wire service. Use @wire in a component’s JavaScript class to specify a Lightning Data Service wire adapter.

The LDS wire adapters are built on User Interface API resources and resides in the lightning/ui*Api modules.

The wire service provisions an immutable stream of data to the component. Each value in the stream is a newer version of the value that precedes it.

Click here for more information about lightning/ui*Api

Syntax

import { adapterId } from 'adapterModule';
@wire(adapterId, adapterConfig)
propertyOrFunction;
  • adapterId (Identifier)—The identifier of the wire adapter.
  • adapterModule (String)—The identifier of the module that contains the wire adapter function, in the format namespace/moduleName. Look at the format! To import a module in JavaScript, use lightning/ui*Api instead of lightning-ui-*-api.
  • adapterConfig (Object)—A configuration object specific to the wire adapter. Configuration object property values can be either strings or references to objects and fields imported from @salesforce/schema.
  • propertyOrFunction—It receives data from the wire service. If a property is decorated with @wire, the results are returned to the property’s data property or error property.

Get Record Data

Imports the adapterId getRecord wire adapter from the adapterModule lightning/uiRecordApi module, which is built on Lightning Data Service, then in adpaterConfig use ‘recordId:’ for particular object and ‘fields:’ property to get fields. Then use function or property to get data and error.

eg. In this example I am getting account record using getRecord adapterID




Follow me on linkedIn and Twitter for such more related post

Comments