Salesforce Decode
Salesforcedecode
Back to questions
LWCAdvancedcacheableapexstale-data

Review Apex @AuraEnabled cacheable=true used with record edit LWC

Real World Scenario

Edit form LWC wires cacheable Apex returning picklist values; users see outdated picklist after admin deactivates values until hard refresh.

Expected Answer

• Never use cacheable=true for data that changes based on admin config mid-session • Picklists from getPicklistValues wire or getObjectInfo are LDS-managed — prefer over custom cacheable Apex • If cacheable required for read-only reference data, document TTL expectations and provide manual refresh • refreshApex only applies to wired Apex — verify wire is used not imperative call • Separate read cacheable endpoints from write imperative endpoints clearly • Add version stamp in admin config changes to bust cache intentionally if needed • Test admin metadata change during active user session in UAT

Follow-Up Questions & Answers

Click to expand — each follow-up includes a direct, interview-ready answer

Direct answer: Never use cacheable=true for data that changes based on admin config mid-session Also consider: Picklists from getPicklistValues wire or getObjectInfo are LDS-managed — prefer over custom cacheable Apex In practice: If cacheable required for read-only reference data, document TTL expectations and provide manual refresh Optimize for scale and operational observability.

Architect Perspective

cacheable=true is a performance contract — misuse creates stale UI harder to debug than slow UI.