Lightning Web Component
LWC: load a record with @wire(getRecord)
Reactive single-record fetch in Lightning Web Components. Cached by the Lightning Data Service so multiple components share one network call.
import { LightningElement, api, wire } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import NAME_FIELD from '@salesforce/schema/Account.Name';
import INDUSTRY_FIELD from '@salesforce/schema/Account.Industry';
export default class AccountSnapshot extends LightningElement {
@api recordId;
@wire(getRecord, { recordId: '$recordId', fields: [NAME_FIELD, INDUSTRY_FIELD] })
account;
get name() { return getFieldValue(this.account.data, NAME_FIELD); }
get industry() { return getFieldValue(this.account.data, INDUSTRY_FIELD); }
}Notes
- Always reference fields via @salesforce/schema imports - hardcoded API names break at deploy time.
- getFieldValue is null-safe; prefer it over manually walking account.data.fields.*.value.