ApexAdvancedldvsoqlgovernor-limits
Handle SOQL query row limit when aggregating child records on LDV parent
Real World Scenario
Account with 45,000 related Task records breaks Account summary Apex that queries all children in single SOQL for activity counts.
Expected Answer
• Never query all children on LDV parent—use roll-up summary or batch pre-aggregation
• Aggregate in SOQL with GROUP BY and selective date filters on indexed ActivityDate
• Maintain Activity_Count__c via trigger or DLRS with nightly reconciliation batch
• Query planner verify selective filter on AccountId plus date range
• CRM Analytics or Data Cloud for historical activity analytics not real-time Apex
• Paginate child queries in UI; server returns counts from rollup field
• Test LDV scenario with synthetic 50k child records in full sandbox
Follow-Up Questions & Answers
Click to expand — each follow-up includes a direct, interview-ready answer
Stay within limits by: Never query all children on LDV parent—use roll-up summary or batch pre-aggregation. Bulkify everything — never query or DML in loops. Maintain Activity_Count__c via trigger or DLRS with nightly reconciliation batch. LDV parent-child queries without limits are production incidents waiting for first mega-account. Optimize for scale and operational observability.
Architect Perspective
LDV parent-child queries without limits are production incidents waiting for first mega-account.