October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Salesforce LWC Data Access: When to Choose LDS, GraphQL, or Apex

For ordinary Salesforce records in an LWC, start with LDS. Use GraphQL for richer queries and Apex when UI API falls short or changes must share a transaction.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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

A practical decision sequence

  1. Check whether a base component covers the interface. Use lightning-record-form or the view/edit form components for a standard record experience.
  2. 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.
  3. Consider GraphQL for query-heavy requirements. Use it when precise fields, filters, relationship traversal, combined query needs, or pagination matter.
  4. Check transaction boundaries. If several record changes must succeed or roll back together, use Apex to implement the combined transaction.
  5. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.