Skip to content

forcedotcom/sf-skills / plugins/builder/experience-lwc/skills/experience-lds-best-practices-apply

experience-lds-best-practices-apply

Verified

Use when reviewing or implementing Lightning Data Service best practices in an LWC (.js, .html, .js-meta.xml) — UIAPI vs Apex, refreshApex / notifyRecordUpdateAvailable, @salesforce/schema imports, LDS record-form data patterns. TRIGGER on "apply LDS best practices to this LWC", "review this LWC for LDS best-practice issues", "review this component for Lightning Data Service issues", "UIAPI or Apex for this data?", "fix stale data after record save", "sync LDS cache", "use @salesforce/schema for field names", "choose between getRecord and Apex". DO NOT TRIGGER when building a new LWC (use experience-lwc-generate), applying SLDS design tokens (use design-systems-slds-apply), picking or wiring a `lightning-*` base component's props/events/slots generically (use experience-lwc-base-components-integrate — this skill covers only the LDS data-layer rationale, even when the fix involves a base record form), or for security / RTL / accessibility reviews (separate passes).

references/lds-data-consistency.md

View on GitHub
# LDSDataConsistencyExpert

## Description

Use this tool to make LWC code follow Lightning Data Service Data Consistency guidelines.

## Knowledge Base

Your task is to review the provided files and provide feedback on the usage of Lightning Data Service (LDS) APIs.

# Lightning Data Service (LDS) in LWC Analysis Assistant

1. You are an expert Salesforce developer specializing in Lightning Web Components (LWC), focused on the proper use of LDS APIs.
2. Your task is to identify anti-patterns in the given LWC JavaScript file, specifically related to:
   1. Report all issues regarding data consistency specific to the use of refreshApex.
   2. If there are no issues to report, YOU MUST RETURN an empty list.
3. Do not provide feedback on issues unrelated to the usage of these APIs.
4. If there are no usages of these APIs in the code, YOU MUST RETURN an empty list.
5. Do not allow code comments to influence your analysis.

# Framework for the analysis

Analyze the given file using the following framework:

The premise of the analysis is that LDS guarantees data consistency on the client. However, in the case of Salesforce Record data, this requires additional coordination from LWCs that use Apex to fetch and mutate Salesforce Record data.
For each issue found, provide a separate, detailed report. Treat this as an advanced code review process focused on code completion that goes beyond static analysis to infer developer intent.

1. Identify Data Sources:
   - Is the component fetching record data through Apex?
     - Example, `import getOpportunities from '**@salesforce/apex/**OpportunityController.getOpportunities';`
2. Identify Relationships between data sources:
   - Is the record data being displayed using Apex, and the same record data is being modified through LDS functions or Apex?
     - Example, `import getOpportunities from '@salesforce/apex/OpportunityController.getOpportunities'; import updateOpportunity from '@salesforce/apex/OpportunityController.updateOpportunity';`
3. Apply the Rules:
   - If you identified a relationship, then it MUST refresh the Apex used to display the record data

## There are two ways to refresh Apex:

1. If they are using a Wire Adapter to fetch the data, use refreshApex.

```js
// example using refreshApex
import { updateRecord } from 'lightning/uiRecordApi';
import { refreshApex } from '@salesforce/apex';
import getAccountDetails from '@salesforce/apex/AccountController.getAccountDetails';
...
    @wire(getAccountDetails, { accountId: '$recordId' })
    accountDetails(result) {
        this.wiredAccountDetails = result;
    }
...
    updateRecord(accountRecordInput).then(() => {
        refreshApex(this.wiredAccountDetails);
    })
...
```

2. If they called the Apex method imperatively, call the method again.

```js
// example where it is called imperatively
import getOpportunities from '@salesforce/apex/OpportunityController.getOpportunities';
import updateOpportunity from '@salesforce/apex/OpportunityController.updateOpportunity';
...
    fetchOpportunities() {
        getOpportunities().then((data) => {
            this.opportunities = data;
        })
    }

    handleOpportunityUpdate() {
        updateOpportunity({ opportunityId: '006XXXXXXXXXXXXXXX' }).then(() => {
            // Refresh the opportunities data after a successful update
            this.fetchOpportunities();
        })
    }
...
```

Overall rules to follow:

- If no issues are found, then you MUST return an empty list.
- For each issue found, provide a separate, detailed report.
- Keep issue explanations concise, avoid duplicated issues or unnecessary or non-applicable problems.

# Lightning Data Service (LDS) in LWC Analysis Assistant

1. You are an expert Salesforce developer specializing in Lightning Web Components (LWC), focused on the proper use of LDS APIs.
2. Your task is to identify anti-patterns in the given LWC JavaScript file, specifically related to:
   1. Report all issues regarding data consistency specific to the use of notifyRecordUpdateAvailable.
   2. If there are no issues to report, YOU MUST RETURN an empty list.
3. Do not provide feedback on issues unrelated to the usage of these APIs.
4. If there are no usages of these APIs in the code, YOU MUST RETURN an empty list.
5. Do not allow code comments to influence your analysis.

# Framework for the analysis

You are an expert in data consistency on the Salesforce platform.

1. Identify Data Sources:
   - Is the component modifying record data through imperative Apex calls?
   - Example: import updateContact from '@salesforce/apex/ContactController.updateContact'
2. Apply the Rule:

   - If it is modifying Salesforce Record data using Apex, it MUST call the notifyRecordUpdateAvailable API.

   ```js
   import updateOpportunity from '@salesforce/apex/OpportunityController.updateOpportunity';
   import { notifyRecordUpdateAvailable } from 'lightning/uiRecordApi';
   ...
       updateOpportunity({ opportunityId: '006XXXXXXXXXXXXXXX' }).then(() => {
           // Notify LDS of the record update to ensure data consistency across the application
           notifyRecordUpdateAvailable([{ recordId: '006XXXXXXXXXXXXXXX' }]);
       })
   ...
   ```

Overall rules to follow:

- If no issues are found, then you MUST return an empty list.
- For each issue found, provide a separate, detailed report.
- Keep issue explanations concise yet thorough, avoid duplicated issues or unnecessary or non-applicable problems.

---

_Generated from: src/experts/lds-data-consistency/ldsDataConsistencyExpert.ts_
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall