Friday, December 16, 2011

Query Error: "System.QueryException: Non-selective query against large object type" in Trigger

Topic in Detail: Sometime when we work with multiple event on task, event or idea object (I got the error on this objects, don’t have idea about others), we got this error.

Main Cause: Field or Data Indexing Related Problem

There can be some causes behind this error as much I have observed, Please update me if you have anything other than this.

Cause 1: The Field or Data is not indexed.

Solution 1: 

When using a field in your "where" clause of a query, it's best to try to have that field indexed by checking the "external ID" checkbox when you define that field. 

Note:  
  • For every object, only a limited number of fields can be indexed: see the online help for the limit. 
  • You can create maximum three External Ids in an Object.
  • The External Id field can be of only two Data Types (Text OR Number).
Cause 2: Null value in some field you are using in your query, related problem.
Solution2:
  • Use condition to skip the null values in your queries and if conditions carefully.
  • Keep event sections Separated and place check for null pointers carefully.

I resolved the exception in my code by this ways.
Please give you your valuable suggestions.
Rectify me if i am wrong somewhere.

Thanks,
Amit Goyal

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.