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
Niraj Kumar 9Niraj Kumar 9 

Trigger is giving error : d by: System.QueryException: Non-selective query against large object type (more than 100000 rows)


Can U please modify this trigger to call Future class. May be this solution work.
Trigger TaskTrigger on Task(after insert, after delete, after undelete) {
    Set<Id> accountIds = new Set<Id>();
    for(Task tsk : trigger.isDelete ? trigger.old : {
    AggregateResult[] groupedResults = [SELECT Count(Id), AccountId FROM Task group by AccountId having AccountId in: accountIds];
    Map<Id,Integer> taksCountMap = new Map<Id,Integer>();
    for (AggregateResult ar : groupedResults)  {
    List<Account> accUpdLst = new List<Account>();
    //Updating the count field
    for(Task tsk: {   
            accUpdLst.add(new Account(Id = tsk.AccountId,count__c = taksCountMap.get(tsk.AccountId)));
    if(accUpdLst.size() > 0) {
        update accUpdLst;

Ray C. KaoRay C. Kao
Here is a hintful article