The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →For ordinary Salesforce records in a Lightning Web Component (LWC), start with Lightning Data Service (LDS). Use its base components for standard forms, its wire adapters or functions for custom interfaces, and its GraphQL wire adapter for focused or relational queries. Choose Apex when UI API does not support the object or operation, or when several record changes must succeed or fail as one transaction.
Which data-access approach fits your requirement?
| Requirement | Preferred approach | Why |
|---|---|---|
| Standard record view, create, or edit form | LDS base components, such as lightning-record-form, lightning-record-edit-form, or lightning-record-view-form |
They provide standard record interfaces with the least custom work. Salesforce’s data guidelines recommend starting with base components. |
| A custom interface for a supported record | LDS wire adapter for reactive data; LDS functions such as createRecord, updateRecord, or deleteRecord for individual changes |
Adapters and functions let you customize the UI while using LDS. Each function call is an independent transaction. Salesforce’s data guidelines |
| A focused query involving related objects, filters, or pagination | LDS-backed GraphQL wire adapter | GraphQL can request specific fields, traverse relationships, express filters, and combine query needs. It can reduce repeated requests. Data guidelines; When to Use the GraphQL Wire Adapter |
| An object or operation unsupported by UI API | Apex | Salesforce names Task and Event as examples of objects not supported by UI API. Salesforce’s data guidelines |
| A criteria-based operation UI API cannot express | Apex | Salesforce gives retrieving a filtered list, such as Accounts whose Amount exceeds a threshold, as an example. Salesforce’s data guidelines |
| Multiple record changes that must commit or roll back together | Apex | LDS functions handle individual operations as independent transactions; Apex can group multiple record operations into one transaction. Data guidelines; GraphQL wire adapter guidance |
| A read that must run at a specific moment, such as after a button click | Imperative LDS function if it supports the operation; otherwise imperative Apex | Imperative calls run when invoked. A wired method provisions a stream, while an imperative Apex call returns a one-time promise result. Data guidelines; Call Apex Methods Imperatively |
Start with the simplest LDS option that meets the need
Use a base component for standard forms
If the component needs a conventional view, create, or edit experience, use an LDS-backed base component before building a custom data layer. Salesforce calls base components the easiest way to work with Salesforce data. They are a strong default when their standard behavior and available customization meet the interface requirement.
As an Amazon Associate I earn from qualifying purchases.
Use adapters or functions when the interface needs more control
For a custom UI over supported records, LDS wire adapters provide reactive data, while functions give the component explicit control over individual mutations. For example, call updateRecord to save one record in response to a user action. Do not treat a sequence of such calls as a single transaction: each call is independent.
Use GraphQL when query shape is the deciding factor
The GraphQL wire adapter is still LDS-backed, but it suits queries that need exact fields, relationship traversal, filtering, or pagination. It can also combine query needs and help avoid repeated requests. If the component both retrieves and searches the same data in the documented scenario, Salesforce recommends using GraphQL consistently rather than mixing Apex and LDS-managed data.
#1 Best Overall
Move to Apex for a genuine platform or transaction gap
Apex is appropriate when UI API cannot support the object or operation, or when multiple record changes need a single transactional outcome. It is also an option for server-side logic that the LDS surface cannot express. Treat Apex as an extension point after checking base components, LDS adapters and functions, and GraphQL—not as the automatic choice for every LWC data request.
Understand how cache and refresh behavior differ
LDS-managed data
LDS caches record data on the client and shares it among components that access the same record. Changes to supported records can be reflected in other components using relevant LDS wires. Salesforce can change the cache lifetime, so application code should not rely on a fixed duration. Lightning Data Service documentation
Rank #2
Apex results
Apex results are not managed by LDS, including results from a cacheable Apex method. When a wired Apex result becomes stale, call refreshApex() with the wire result. After an imperative Apex operation, call the method again when fresh results are needed. If records changed by Apex also appear in LDS-backed components, call notifyRecordUpdateAvailable(recordIds) so those components can update. Avoid unnecessary refreshes: refreshApex() makes a server request. Wire Apex Methods to Lightning Web Components; Client-Side Caching of Apex Method Results
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Do not assume Apex and LDS share a cache or data store. Mixing their results can lead to inconsistent data, including in online or offline scenarios. Choose a consistent access strategy for data that the component retrieves and searches.
Rank #3
Account for security rather than assuming the two paths behave alike
LDS and UI API
LDS-backed UI API components and adapters apply record sharing, object-level permissions (CRUD), and field-level security (FLS). When this built-in behavior covers the requirement, LDS is the simpler choice for user-facing record access. Lightning Data Service documentation
Apex
Apex requires deliberate access control. Sharing declarations govern record-level access; database access modes or stripInaccessible() address object and field permissions. Check the guidance for the Salesforce release and API version your code targets, because Apex defaults can vary by API version. Secure Apex Classes
Choose wire or imperative calls based on control flow
Choose a wire for reactive data
A wire is useful when the view should receive a stream of data as its configuration or underlying values change. Wired Apex methods must be annotated @AuraEnabled(cacheable=true) and must only read data. Use an LDS wire adapter when the data is supported and LDS behavior fits; use a wired Apex method when the server-side read requires Apex. Wire Apex Methods to Lightning Web Components
Choose imperative invocation for an explicit action
Use an imperative call when the component should decide exactly when to invoke the operation—for instance, after a user clicks a button—or when performing a mutation. Imperative Apex resolves to one promise result; it does not make its returned data LDS-managed. If an LDS function can perform the requested operation, it may be the more direct imperative option. Call Apex Methods Imperatively
Quick Recap
Best Value
A practical decision sequence
- Check whether a base component covers the interface. Use
lightning-record-formor the view/edit form components for a standard record experience. - For a custom UI, confirm that UI API supports the object and operation. If it does, use an LDS adapter for reactive reads or an LDS function for an individual mutation.
- Consider GraphQL for query-heavy requirements. Use it when precise fields, filters, relationship traversal, combined query needs, or pagination matter.
- Check transaction boundaries. If several record changes must succeed or roll back together, use Apex to implement the combined transaction.
- Plan refresh and security behavior. Know which cache owns each result, how stale data will be refreshed, and how Apex enforces sharing, CRUD, and FLS.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




