Salesforce Decode
Salesforcedecode
Back to questions
LWCIntermediateimperativearchitecturetesting

Structure Apex controller layer for LWC with single responsibility methods

Real World Scenario

One @AuraEnabled god method returns header, tabs, related counts, and picklists causing heap errors and untestable LWC.

Expected Answer

• Separate cacheable read methods per concern: getHeader, getRelatedCounts • LWC wires and imperatives map to focused Apex methods • Service layer between controller and SOQL for reuse in batch • Each method enforces row limit and stripInaccessible • Jest mocks per method isolating component test doubles • Document Apex method catalog mapping to LWC components • Deprecate god method with phased LWC migration

Follow-Up Questions & Answers

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

Main difference: use case and scale. Separate cacheable read methods per concern: getHeader, getRelatedCounts. LWC wires and imperatives map to focused Apex methods. Pick based on your integration pattern and team capability. God Apex method mirrors god LWC—split at API boundary for performance and testability. Balance speed of delivery with maintainability.

Architect Perspective

God Apex method mirrors god LWC—split at API boundary for performance and testability.