+ 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 : trigger.new) {
    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: trigger.new) {   
            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