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
lakshmi.sf9lakshmi.sf9 

Asynchjobs filters

Hi,

DateTime todayDate = system.today();
if ([SELECT count() FROM AsyncApexJob WHERE CreatedDate =:todayDate AND JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing')]<5)

getting error in this query as

caused by: 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):

can any one please help on this.Its urgent
Vamsi KrishnaVamsi Krishna
Hi, since you are checking if the count is less than 5, you don't need to get the total count.. you can limit your query to a get few records matching the condition say only 10 and then compare the count..

if ( [ SELECT count() FROM AsyncApexJob WHERE CreatedDate =:todayDate AND JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing') limit 10 ] < 5 )