Salesforce Decode
Salesforcedecode
Back to questions
ApexAdvancedgovernor-limitstriggersmonitoring

Implement cumulative limit tracking across trigger and helper call stack

Real World Scenario

Account trigger delegates to three services each querying related data. Total SOQL exceeds limit but each service appears healthy individually.

Expected Answer

• Central LimitMonitor utility logging cumulative queries at stack depth • Trigger handler passes shared QueryCache map to all services • Budget per trigger: max 20 SOQL documented in handler header • Fail fast when budget 80% consumed with clear error message • Architecture review when trigger exceeds three service delegations • Integration tests assert total SOQL count not per-class only • Static analysis detecting SOQL in service methods without cache param

Follow-Up Questions & Answers

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

Direct answer: Central LimitMonitor utility logging cumulative queries at stack depth Also consider: Trigger handler passes shared QueryCache map to all services In practice: Budget per trigger: max 20 SOQL documented in handler header Optimize for scale and operational observability.

Architect Perspective

Service decomposition without shared cache multiplies SOQL—budget at trigger entry point.