How do administrators manage high-volume case databases to prevent governor limit bottlenecks and slow queries?
Answer
Basics: Governor limits cap what one transaction may do (for example 50,000 rows returned by SOQL, 100 synchronous SOQL queries), but slowness on millions of cases is mostly about query selectivity, locking and sharing. This is called Large Data Volume (LDV) design.
How it works:
- Indexes: standard indexed fields include Id, Name, OwnerId, CreatedDate, SystemModstamp, lookup and master-detail fields, RecordTypeId and External IDs. Support can create custom indexes.
- Selectivity: a filter on a standard index is selective if it returns under roughly 30 percent of the first million records (and 15 percent beyond); for custom indexes about 10 percent and 5 percent, with caps. Verify exact current thresholds.
- Use Query Plan in the Developer Console to check cost.
- Archive closed legacy cases to Big Objects, an external store or a data platform; delete with Bulk API hard delete.
- Skinny tables (via Support) speed reads on wide objects.
Advanced / deep dive: Non-selective queries in triggers on objects over 200,000 records throw errors. Avoid negative filters (!=, NOT IN), leading wildcards (LIKE '%x'), null checks and formulas on unindexed fields. Skew: more than about 10,000 cases owned by one user (ownership skew) or children under one parent (parent skew, for example one Account) causes row lock and sharing recalculation delays; spread ownership across queues or integration users. Use Bulk API 2.0 and PK chunking for exports. Defer sharing calculations during bulk loads. Move heavy aggregation to reports with filters, CRM Analytics or an external warehouse. Async SOQL is retired.
Code / config example:
-- Selective: indexed date filter plus owner
SELECT Id, CaseNumber, Status FROM Case
WHERE CreatedDate = LAST_N_DAYS:30 AND OwnerId = :queueId
-- Avoid: SELECT Id FROM Case WHERE Status != 'Closed' (low selectivity, negation)
Hidden gotchas & must-remember points:
- Governor limits are per transaction; LDV issues are mostly timeouts and locks.
- Query timeouts occur around two minutes.
- Formula fields and cross-object formulas cannot be indexed unless deterministic and requested.
- Storage counts: most records use about 2 KB data storage.
- Deleted records stay in the Recycle Bin for 15 days.
- Archiving must keep reporting and compliance needs in mind.
Best practice: Design queries around indexed filters, archive by policy, and load-test with production-sized data.