Nonselective query fails on Apex trigger but succeeds in anonymous Apex and standalone query
|Knowledge Article Number||000187995|
Difference between nonselective query and anonymous Apex and standalone query
Anonymous Apex and standalone queries access the cache, so it's possible for these queries to actually succeed when they typically wouldn't if the records weren't cached. Triggers, on the other hand, don't access the cache, so they issue a new query for each and every call.
Why anonymous Apex or standalone queries succeed