Lightning Data Service provides built-in record access and caching without Apex. LDS is ideal for simple record display and editing.
import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
const FIELDS = ['Account.Name', 'Account.Phone', 'Account.Industry'];
export default class AccountViewer extends LightningElement {
@api recordId;
@wire(getRecord, { recordId: '$recordId', fields: FIELDS })
account;
}
<template>
<template if:true={account.data}>
<p>Name: {account.data.fields.Name.value}</p>
<p>Phone: {account.data.fields.Phone.value}</p>
</template>
<template if:true={account.error}>
<p class="error">Error loading record</p>
</template>
</template>
Use lightning-record-edit-form to handle record updates without Apex.
<template>
<lightning-record-edit-form
record-id={recordId}
object-api-name="Account"
onsuccess={handleSuccess}
onerror={handleError}
>
<lightning-messages></lightning-messages>
<lightning-input-field field-name="Name"></lightning-input-field>
<lightning-input-field field-name="Phone"></lightning-input-field>
<lightning-button type="submit" label="Save" variant="brand"></lightning-button>
</lightning-record-edit-form>
</template>
import { LightningElement, wire } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';
export default class AccountInfo extends LightningElement {
@wire(getObjectInfo, { objectApiName: ACCOUNT_OBJECT })
objectInfo;
}
import { LightningElement, wire, track } from 'lwc';
import { getPicklistValues } from 'lightning/uiObjectInfoApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';
import INDUSTRY_FIELD from '@salesforce/schema/Account.Industry';
export default class IndustrySelector extends LightningElement {
@track industryOptions;
@wire(getPicklistValues, {
recordTypeId: '012000000000000AAA',
fieldApiName: INDUSTRY_FIELD
})
wiredPicklist({ error, data }) {
if (data) {
this.industryOptions = data.values;
}
}
}
Use Apex when data requires complex aggregation, custom search, or non-CRUD business logic.
lightning/uiRecordApi for simple display and editlightning-record-edit-form for standard edit UXgetRecord, getObjectInfo, and getPicklistValues