Salesforce Decode
Salesforcedecode
Back to questions
ApexIntermediategovernor-limitserror-handlinglwc

Handle governor limit exceptions gracefully in user-facing Apex controllers

Real World Scenario

LWC search runs Apex returning 10k rows. Users see cryptic "Apex heap size too large" instead of actionable message.

Expected Answer

• Catch LimitException at service boundary with user-safe message • Paginate and limit result sets server-side before returning to LWC • Throw AuraHandledException with support reference Id not raw limit message • Proactive guard: if estimated rows exceed threshold return partial with warning flag • Log limit snapshot at failure for ops investigation • Design API max page size enforced server-side not client parameter • Load test controller at projected volume before release

Follow-Up Questions & Answers

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

Main difference: use case and scale. Catch LimitException at service boundary with user-safe message. Paginate and limit result sets server-side before returning to LWC. Pick based on your integration pattern and team capability. Limit exceptions to users mean missing pagination—fix architecture not just error message. Balance speed of delivery with maintainability.

Architect Perspective

Limit exceptions to users mean missing pagination—fix architecture not just error message.