Wire Adapters
Wire adapters are functions that provide data to your components. Salesforce provides built-in wire adapters for UI API and custom Apex methods.getRecord Wire Adapter
Retrieves a single record with specified fields.Parameters
- recordId (String): The record ID (prefixed with
$for reactive binding) - fields (Array): Required fields to retrieve
- optionalFields (Array): Optional fields to retrieve (won’t cause errors if unavailable)
Return Value
Returns an object with:- data: The record object with requested fields
- error: Error information if the request fails
getRecords Wire Adapter
Retrieves multiple records in a single request.Parameters
- records (Array): Array of record configurations, each containing:
- recordIds (Array): Array of record IDs to retrieve
- fields (Array): Required fields for these records
- optionalFields (Array): Optional fields for these records
Return Value
Returns an object containing:- data: Object with
resultsarray containing each record’s data - error: Error information if any request fails
Reactive Parameters
Prefix properties with$ to make them reactive. The wire service automatically re-executes when reactive parameters change.
- Static Parameter
- Reactive Parameter
Wire to Property vs Function
- Wire to Property
- Wire to Function
- You only need to display the data
- You don’t need to process the results
this.contacts.dataKey Features
Reactive
Automatically updates when parameters change
Cached
Shares data across components and reduces server calls
Declarative
No manual API calls or lifecycle management needed
Immutable
Data is read-only, ensuring predictable state management
