Is it true that "System.QueryException: non-selective query" is only ever thrown from a trigger?

If so, where is this documented and what happens when an identical query (one that throws "System.QueryException: non-selective query" from a trigger execution context) is run in a different type of execution context?

Why is the behaviour different?

2 Answers 2


A non-selective query executed in a different context will still cause issues.

For example, in batch apex you will get this error "SQLException ORA-01013" https://help.salesforce.com/HTViewSolution?id=000175555&language=en_US

In a controller, depending on the amount of records, the user experience will be very bad as depending on the amount of records, it could take minutes to respond.

At least in the case of batch apex, we could tell the behavior is a bug that has never been fixed, as that is an internal error that should not be shown to a user.


Query selectivity is only enforced in triggers, and only when the target object has over 100k rows. You will not get this exception in other cases.

However there is an overall transaction timeout, which PepeFloyd's answer covers quite well. It's by default a 2 minute timeout in most cases, which is quite different from enforcing query selectivity, but the same things that improve selectivity also improve overall runtime. These issues are related and quite similar from many aspects, but technically a distinct and more generous limit.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .