You need to sign in to do that
Don't have an account?
Niraj Kumar 9
Trigger is not counting closed activity
Hi,
Below is my trigger, its not counting the closed Activity.
Need your help.
Below is my trigger, its not counting the closed Activity.
Need your help.
trigger AccountCounttask on task (after insert, after delete) { Set <Id> AccountIDs = new Set <Id> (); if(Trigger.isInsert ){ for(Task tsk1: Trigger.new){ if(tsk1.WhatId <> NULL && tsk1.WhatId.getSobjectType() == Account.getSObjectType()){ AccountIDs .add(tsk1.WhatId); } } } if(Trigger.isDelete ){ for(Task tsk1: Trigger.old){ if(tsk1.WhatId <> NULL && tsk1.WhatId.getSobjectType() == Account.getSObjectType()){ AccountIDs .add(tsk1.WhatId); } } } if(AccountIDs.size()>0) ActivityTriggerHandler.UpdateActivityAccount(AccountIDs); // Recompute the Activities for Account }
@future public static void UpdateActivityAccount(set<Id> AccountIDs ){ MAP <Id,integer> AccountCntMap = new MAP <Id, integer>(); integer count; for(ID id1: AccountIDs ){ AccountCntMap .put(id1, 0); } for(Task tsk1: [select WhatId, Id from Task where WhatId IN :AccountIDs ]){ count = AccountCntMap .get(tsk1.WhatId) + 1; AccountCntMap .put(tsk1.WhatId, count); } for(Event ev1: [select WhatId, Id from Event where WhatId IN :AccountIDs ]){ count = AccountCntMap .get(ev1.WhatId) + 1; AccountCntMap .put(ev1.WhatId, count); } LIST <Account> AccUpd = new LIST <Account>(); for(Account Acc1: [SELECT Id, Count_of_Activity__c FROM Account WHERE Id IN :AccountIDs ]){ count = AccountCntMap .get(Acc1.Id); Acc1.Count_of_Activity__c = count; AccUpd .add(Acc1); } Database.update(AccUpd ); }
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.
All Answers
and pass the parameter in future method then u do
Thanks,
Srinivas
- Please mark as solution if your problem is resolved.