How do you design for large data volumes in Salesforce? Explain selective queries, skinny tables, and indexes.
Suggested answer
Selective Queries: A SOQL query is selective when it filters on an indexed field and the estimated result set is below a threshold (approximately 10% of total records or 333K records). Non-selective queries trigger a full table scan and can time out on large objects. Always filter on CreatedDate, Id, or other indexed fields first.
Indexes:
- Standard indexes: Automatically created on Id, Name, OwnerId, CreatedDate, SystemModstamp, RecordTypeId, and Master-Detail/Lookup fields.
- Custom indexes: Requested via Salesforce Support on specific fields. Do not index fields with low cardinality (checkbox, picklist with 2 values) — selectivity is key.
- Unique indexes: Enforce uniqueness at the database level and are indexed.
Skinny Tables: A Salesforce-managed internal table containing a subset of frequently queried fields from a large object. Queries against skinny table fields are faster because fewer columns are scanned. Available for custom and some standard objects. Must be requested via Salesforce Support. Skinny tables are synchronised automatically; no additional code is needed once created.
Query Plan Tool: Available in the Developer Console. Reveals whether a query will use an index or full table scan, and estimates query cost.
Practice content for interview preparation; not an official vendor answer. Verify details against current product documentation.
Community comments (0)
No comments yet.
Sign in or create a free account to add a comment. Comments are moderated before they appear.