0

Background :

  • I have a object(Foo__c) with two columns(Value__c, Type__c). Type__c is a picklist, with two options(A and B) and Value__c is a text field.
  • Running into Non-Selective query error when running query like this SELECT Value__c FROM Foo__c WHERE Type__c = 'A' LIMIT 1 in after update trigger on Contact object.

So, I looked into the Make SOQL query selective article and came up with the below calculation.

Query 1:(Total number of records in Object)

SELECT COUNT(Id) FROM Foo__c

1551449

Query 2:(Total number of records present in object where Type__c = 'A')

SELECT COUNT(Id) FROM Foo__c WHERE Type__c = 'A'

807049

Query 3: (Total number of records present in object where Type__c = 'B')

SELECT COUNT(Id) FROM Foo__c WHERE Type__c = 'B'

744400

Maximum number of records Query 2 or Query 3 can return before the query is considered non-selective is 127,552, Is that right?

//Applying 10% of first one million and 5% of remaining records 
(0.1*1000000)+((1551449-1000000)*0.05) = 127,552

That means, if I make Type__c field indexed, it won't solve my non-selective query errors that I am running into in trigger context (for query 2 and 3), right?

I am going through Make SOQL query selective but still want to make sure that what I am interpreting is correct.

NOTE: I ran Query 2 and 3 using Bulk API

2
  • Your numbers could use a bit more context. – Adrian Larson Sep 28 '19 at 20:01
  • @AdrianLarson added – javanoob Sep 28 '19 at 20:04

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.