A selective query filters on an indexed field with a condition narrow enough that the optimiser uses the index instead of scanning the table. Standard indexes include Id, Name, OwnerId, CreatedDate, SystemModstamp, lookup fields and external ids, and custom indexes can be requested. Leading wildcards, negative operators, null checks and most formula fields defeat indexes. In triggers on large objects, non selective queries fail outright.
Why interviewers ask this
Large data volumes expose query design that worked fine in a sandbox. The interviewer wants to know whether you understand indexes on the platform, what defeats them, and how to check a query plan. The fact that a non selective query inside a trigger on a large object throws an exception, rather than just running slowly, is the practical detail that shows you have worked with real data volumes.
How to structure your answer
- Define selectivity in terms of indexes and thresholds.
- Name the standard indexed fields and custom index options.
- List the patterns that defeat an index.
- Explain how you check with the query plan tool.
Example answer
A query is selective when its filter uses an index and narrows the result enough that the optimiser chooses the index over scanning every row. The thresholds are a share of the object's records, so a filter that is selective on a small object may not be on one with millions of rows. Standard indexes cover fields like Id, Name, OwnerId, CreatedDate, SystemModstamp, record type, lookup and master detail fields, plus external id and unique fields. Beyond that you can ask Salesforce Support for a custom index. What defeats an index matters just as much: leading wildcards in a LIKE, not equal and NOT IN filters, filtering for null, and most formula fields. It matters because in a trigger, a non selective query against an object with more than two hundred thousand records does not just run slowly; it throws an exception and fails the save. I check queries with the query plan tool in the developer console. On one org I fixed a failing trigger by filtering on an external id and a date range.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- How would you query a large object for records where a field is blank?
- What is a skinny table, and when would you ask for one?
- How would you handle a report that needs to scan millions of rows?
Related salesforce developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions