You need to sign in to do that
Don't have an account?
lalit kumar 11
Not able to count tasks on account
Hi,
I am trying to make a count of tasks on a custom field (total_tasks__c) on Account. I am not sure why its not showing the count. Below is the code.
trigger taskcount on Task (after insert) {
set<id> setid = new set<id>();
list<account> acc3 = new list<account>();
for(task t :trigger.new){
if(string.valueof(t.whatid).startsWith('OO1') & t.whatid != null)
{
setid.add(t.whatId);
}
for(account acc1 :[select id,(select id from tasks) total_tasks__c from account where id in:setid]){
if(acc1.Tasks.size()>0)
acc1.total_tasks__c = acc1.tasks.size();
acc3.add(acc1);
}
}
update acc3;
}
Please help to resolve the issue.
I am trying to make a count of tasks on a custom field (total_tasks__c) on Account. I am not sure why its not showing the count. Below is the code.
trigger taskcount on Task (after insert) {
set<id> setid = new set<id>();
list<account> acc3 = new list<account>();
for(task t :trigger.new){
if(string.valueof(t.whatid).startsWith('OO1') & t.whatid != null)
{
setid.add(t.whatId);
}
for(account acc1 :[select id,(select id from tasks) total_tasks__c from account where id in:setid]){
if(acc1.Tasks.size()>0)
acc1.total_tasks__c = acc1.tasks.size();
acc3.add(acc1);
}
}
update acc3;
}
Please help to resolve the issue.
Amit Chaudhary 8
Please update your code like below
Let us know if this will help you