+ Start a Discussion

caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows...

Here i am getting "System.QueryException: Non-selective query against large object type (more than 100000 rows...) "

My query is Select Id, Name from Account where Parent__c IN: SETofAccountID

Any luck ?

Chandra Sekhar CH N VChandra Sekhar CH N V
Couple of things here:

1) You have hit Apex governor limit. As the total number of records retrieved by SOQL query is 50,000. Also total number of records processed as a result of DML statements, Approval. Process or database.emptyRecycleBin 10,000.

2) You need indexes for all of the fields you're using if you're going to use SOQL. This means that they must all be marked as External ID or have custom indexes created.

3) You can try adding filters to your query which may reduce records to some extent.

PLease go through belo link for further information:

Alexander TsitsuraAlexander Tsitsura
Hi thoriyas,

You need add to your where statement index fields.
Try to add "IsDeleted = false" to you where statements, if it not help, try to add filter out null value "Parent__c != NULL", and if it's not help try to add CreatedDate to to where Statement "CreatedDate > LAST_N_YEARS:5".
Select Id, Name from Account where Parent__c IN: SETofAccountID AND isDeleted = false AND Parent__c != NULL AND CreatedDate > LAST_N_YEARS:5

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.


Thanks for the replay Alexander!

I have tried your solution as you given... but some how it's not working for me, let me expalin my case in detail..

I have self-lookup in account object.. parent__c is self lookup field.. now i have greated 1000+ account under the one account. it means one parent account has 1000+ child account. now i'm tring to get child record based on parent id(Self account) and my org has 100K+ record.

It's working fine if i do query like [SELECT ID, NAME FROM ACCOUNT WHERE NAME = 'TEST'];

Any luck?




Ketankumar PatelKetankumar Patel
I am not sure about your requirments but the way you describe in your last comment. You should use Apex batch where you can process upto 50M of records. You can also call your batch from your trigger but you need to keep in mind batch governor limits.