0

I'm getting exception in following query,

List<Background_Search__c> lstbgs = [SELECT id FROM Background_Search__c WHERE
                                     AIT_Selected_for_Random_Search_Audit__c = true 
AND CreatedDate>2014-12-04T00:00:00.000Z ORDER BY id DESC LIMIT 1];

1 Answer 1

2

You attempt to query big collection and too many records are potential match. Your query in Salesforce need to be as selective as possible - this mean return only records that match your criteria and it should use field mark as "indexed"(Id, externalId etc).

Please check:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_VLSQ.htm

2
  • Thanks for your reply but when i tried same query on developer console it shows only 5 records this time than how can i ensure that it returns big collection ? Oct 19, 2015 at 10:35
  • 2
    Its not about number of returned records but rather size of collection you query against. You see - the bigger table you query is, more operations need to be performed to filter out records. You should try use some Indexed field in your WHERE statement(if possible). Oct 19, 2015 at 10:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .