+ Start a Discussion

Non-selective query against large object type (more than 100000 rows)

Hi Every one,


I am facing below issue with trigger.Trigger is ment for the below functionality.


when I try to insert or update any record in one custom object(forecasting__c) and this insert/Update of record in Forecasting has to reflect in the another custom object called VP_Approval__c.




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)

Trigger.VPApprovalCreateUpdateValues: line 92, column 1


In line 92 I have the below query:


public List<aggregateResult> forecastListQ = [select  sum(Manager_s_Amount__c) ManagerAmount, sum(Sales_executive_Amount__c) SalesAmonut, sum(Pipeline_Amount_ThisMonth__c) PipelineMonthAmount, sum(Amount__c) amount, Branch1__c, Product_Family1__c, Target_for__c, Months__c, Quarter__c, CALENDAR_YEAR(Close_Date__c) year from Forecasting__c where (RecordTypeID =: RecordTypeIDvalue) and  Branch1__c IN :branchSet and Branch1__c != null and Product_Family1__c IN :prodFamilySet and Product_Family1__c != null and Target_For__c IN :targetForSet and Target_For__c != null and Quarter__c IN :quarterSet and Quarter__c != null and CALENDAR_YEAR(Close_Date__c) IN :yearset and (RecordTypeID =: RecordTypeIDvalue) group by Product_Family1__c, Branch1__c,Target_for__c,Months__c,Quarter__c, CALENDAR_YEAR(Close_Date__c)]; 


This problem I am getting when I have more than 50000 records.


Please some one sugget me to avoid this error.


Thanks in Advance.


why dont you try limiting the query

I'm going to assume that you have done all of the obvious things listed here:




SFDC has a very hard time querying where a field is equal to null, particularly when there is lots and lots of data. Think about it - the database can't do an index search because there isn't a value to index on.


So of course you're checking to make sure that none of your fields include a null value.


Howver, what I've seen when this error comes up is that the set I am query against includes a null value.


It's worth checking, anyway.


Good luck!