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
LogeshLogesh 

Reg: Custom Indexing and querying large number of records

Hi Friends,

 

I'm using an indexed custom field in my soql query to avoid non - selective query error. The query is structured as below

 

sObjectType customObj_name = [SELECT Id,customfield1__c from customObj WHERE Indexed-customfield__c LIKE 'value%'ORDER BY customfield1__c DESC LIMIT 1];

 

It worked fine for 7 months. Then suddenly non - selective query error started occuring.

 

Later I went through the BEST PRACTICES for Handling Large Data Volumes and found that indexed custom field stops working and throws error when it exceeds the threshold limit for 'LIKE' operator in 'WHERE' Clause. That is, the threshold for 'LIKE' operator is 100,000 records of the total records it process. In my scenario, it crosses the threshold and custom indexing stops working and throws error - non selective error.

 

But My question is when I use the same query in the SOQL for Loop like below

 

for(customObj__c co:  [SELECT Id,customfield1__c from customObj WHERE Indexed-customfield__c LIKE 'value%' ORDER BY customfield1__c DESC LIMIT 1] ){

//code to process

}

 

Will this process without throwing error?

I learnt that it process records in multiples of batches through internal calls to query() and querymore().

What is the maximum number of records processed by query() calls and querymore() calls, that is called from SOQL - for Loop?

Is there any other way to process the maximum number of records efficiently from a single object?

Just in curiosity, I want to know -  What is the maximum number of records, a custom object can hold in Salesforce Unlimited Edition? And is there a way to query all the records efficiently from that kind of custom object?

 

Thanks,

Logesh