function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
allen.zhangyilunallen.zhangyilun 

System.QueryException: Non-selective query against large object type for Pricebook2

10:20:24.169 (169594000)|SOQL_EXECUTE_BEGIN|[26]|Aggregations:0|select Id, Name, isStandard from Pricebook2 where ((Name != null and Name = :tmpVar1) or isStandard = true)
10:20:24.174 (174329000)|EXCEPTION_THROWN|[26]|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)
10:20:24.174 (174692000)|FATAL_ERROR|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)

 How can I set a external ID on pricebook2?

liron169liron169
In the field properties you have under 'General Option' checkBox 'External ID'.
Checking this option will set the field as external ID
allen.zhangyilunallen.zhangyilun

Thank you liron, but it's "

select Id, Name, isStandard from Pricebook2

" the standard pricebook2 object, I'm afraid their don't have an external ID field.

liron169liron169

Sorry, didn't notice it's standard object.

I don't think you can define standard fields as external ID.
You can create custom field on the object (than maybe populate it with workflow), and define the custom field as external ID.

However, I don't sure if it will solve the exception you get. as the field Id and Name are already index by default.
Maybe the solution should be - adding filter in your SOQL query.

allen.zhangyilunallen.zhangyilun

Liron, 

actually just tried that I'd created an external text Name__c, to copy the value from standard name, unfortrnately still the same exception, quite strange problem, the same code had no problem in another sandbox under the same production, already opened a case to Salesforce.

liron169liron169

This exception occur when you query on large table (more than 100K), you can try use the SQL little different and it might solve it.

 

read here:

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_VLSQ.htm

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_loops_for_SOQL.htm

 

something like this

 

for (Account[] tmp : [SELECT Id FROM Account WHERE Name = 'yyy']){
//do something with tmp
}
allen.zhangyilunallen.zhangyilun

Yes, I'd googled too, but it's pricebook and the whole instance only have two price books and price books never have too much.