Skip to main content
We have a production org with a managed packaged installed that is working fine.

A sandbox is created from this production org with no data and we see the following error when saving a new Case:

Apex trigger XXXXX.MC_CaseTrigger caused an unexpected exception, contact your administrator: XXXXX.MC_CaseTrigger: execution of AfterInsert caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): (XXXXX)

This is the final statement in the debug log, so I guess this is what causes the problem:

15:23:46.313 (2313202218)|SOQL_EXECUTE_BEGIN|[8]|Aggregations:0|select id from CaseRoutingRequest__c

So it is selecting all Ids from CaseRoutingRequest__c. I know this is not ideal and the query should have a limit added, however there is change control in place around this managed package preventing change for the time being and it shouldn't be a problem because...

When I execute the same select in developer console it runs fine and comes back with zero rows.

There are no CaseRoutingRequest__c objects present, so why is Salesforce giving us this error? Is it undocumented behaviour? Is it a bug? Why does it work in some orgs but not this one?
4 answers
  1. Jan 28, 2015, 9:13 AM

    The first part is as follows, but it only gets to line 8:

    trigger MC_CaseTrigger on Case (after insert, after update) {

    TraceUtils.addMessage('Start of MC_CaseTrigger at: ' + System.now().getTime());

    Case[] cases = Trigger.new;

    XXXXRouting__c cs = XXXXRouting__c.getInstance(); //retrieving a custom setting here

    List<CaseRoutingRequest__c> existingCaseRoutingRequests = [select id from CaseRoutingRequest__c]; //fails here

    set<Id> existingCaseRoutingRequestIds = new set<Id>();

    for(CaseRoutingRequest__c c : existingCaseRoutingRequests){

    existingCaseRoutingRequestIds.add(c.Id);

    }

     
0/9000