2

I'm running a very simple SOQL query which I've renamed objects and included here:

List <ObjectA__c> allRecords= [
select name, Id,Contact__c,...
from ObjectA__c
where Contact__c IN 
(SELECT Contact__c FROM ObjectB__c WHERE id IN :idList) 
];

ObjectB has only 300 records, objectA has over 200k, so it's clearly that object that's causing the problem.

id is indexed, obviously, and objectB's contact field is a master-detail so that's indexed too, and cannot include a null.

I'm open to any suggestions that might help. Troubleshooting has only produced this error in imports (where the idList is built off trigger.new) and running the code manually in anon apex runs fine without problems.

I'm running out of "things to try" so would welcome advice.

3
  • 2
    So just thought I'd share, I just learned that the "can not query an object with over 100000 records with a non-selective query" only happens in triggers, never anon-apex or other methods of called classes (unless they're called from a trigger). I put my code into a trigger and was able to cause it to fail, so now I'm able to troubleshoot and work on a solution. – ScriptMonkey May 14 '14 at 14:29
  • what happens if you do the nested query upfront (so as a separate query)? – Guy Clairbois May 15 '14 at 10:56
  • 1
    @Guy Actually long ago moved on from this issue, but wanted to drop a note to say thanks for offering to help :) – ScriptMonkey Aug 10 '17 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.