You need to sign in to do that
Don't have an account?
Chad Moutes
Apex Trigger to Count Tasks Not Working
I have an Apex Trigger that I am creating that is to count the number of Tasks that are on an Account, the code is listed below.
I keep getting an error that states: Compile Error: unexpected token: 'FROM' at line 21 column 66
Any help would be greatly appreciated.
trigger SumTotalActivitesOnAccount on Task (after insert, after update, after delete) { set<Id> set_Id = new set<Id>(); List<Account>acc_list = new List<Account>(); if(Trigger.isInsert || Trigger.isUpdate) { for(Task T:trigger.new){ set_Id.add(T.What); } } else if(Trigger.isDelete){ for(Task T:Trigger.old){ set_Id.add(T.What); } } if(Trigger.isAfter && (Trigger.isUpdate || Trigger.isInsert || Trigger.isDelete)){ acc_list=[SELECT Id, Sum_Total_Activities__c, (SELECT Id, FROM Tasks) FROM Account WHERE Id IN :set_Id]; for(Account acc: acc_list){ if(acc.Tasks.size()>0) acc.Sum_Total_Activities__c = acc.Tasks.size(); else acc.Sum_Total_Activities__c = 0; } if(!acc_list.isEmpty()) update acc_list; } }
I keep getting an error that states: Compile Error: unexpected token: 'FROM' at line 21 column 66
Any help would be greatly appreciated.
set_Id.add(T.WhatId);
also, add the whatid to set only if it is account id by checking.
if ((T.WhatId + '').startsWith('001'))
All Answers
(SELECT Id, FROM Tasks) this should be replaced to
(SELECT Id FROM Tasks)
Please help lol
set_Id.add(T.WhatId);
also, add the whatid to set only if it is account id by checking.
if ((T.WhatId + '').startsWith('001'))