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
Frank Jordan 14Frank Jordan 14 

System.QueryException: Non-selective query against large object type (more than 100000 rows) Help?

I have a trigger that updates a check box on a task when it is the most recent task created by  the account owner. I am getting the following error: System.QueryException: Non-selective query against large object type (more than 100000 rows). I even added a condition in my query where the created date must be after May of this year, and i know for a fact that there arent more than 100,000 rows. Any idea?
 
trigger LastActivityByAccountOwner on Task (after insert, after update) {

    
List<Task> TasksToUpdate = new List<Task>{};
 
boolean firstRecord = true; 
for(Task ttu : [Select Id, Last_activity_by_account_owner__c , Same_as_Account_Owner__c 
                from Task where Same_as_Account_Owner__c = true AND DAY_ONLY(createddate)>2016-05-01 
                ORDER BY createddate DESC ])
{
if(firstRecord)
{
ttu.Last_activity_by_account_owner__c = True;
firstRecord = false;
}
else
ttu.Last_activity_by_account_owner__c   = False;
 
TasksToUpdate.add(ttu);
 }
}

 
badibadi
Change the date comparison part of query to CreatedDate > 2016-05-08T00:00:00Z and try
Let me know if that does not work
Frank Jordan 14Frank Jordan 14
That worked! Thanks! [Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: Description: \\psf\Home\Desktop\Kabbage_Logo_Stacked_50x50.png] Frank Jordan Salesforce Administrator C: 678.602.7226 www.kabbage.com