Suggested answer

Non-selective queries scan the full table. Triggers include: filtering on non-indexed fields, using LIKE '%value%' (leading wildcard prevents index use), using OR across non-indexed fields, or the estimated result set exceeds selectivity thresholds.

Optimisation strategies:
1. Filter on indexed fields first: Id, CreatedDate, OwnerId, Master-Detail fields, custom indexed fields.
2. Avoid leading wildcards: Name LIKE '%Corp' forces a full scan. Use Name LIKE 'Corp%' instead.
3. Use LIMIT: Always add a LIMIT clause to test queries and production queries that don't need all records.
4. Avoid SELECT *: Query only the fields needed. Reduces data transfer and heap usage.
5. Query Plan Tool: Check "Cost" in Developer Console — cost > 1 indicates a potentially non-selective query.
6. Avoid cross-object SOQL in loops: Use relationship queries (SOQL with nested sub-queries) to retrieve parent/child data in one query.
7. Semi-joins and anti-joins: Use WHERE Id IN (SELECT ...) to reduce round trips.

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.

Plain text only, 3–2000 characters. A moderator reviews every comment before it is published.