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
sindhu@demo.comsindhu@demo.com 

Trigger on Activities in "Account" Object

Hi Everyone,
 I have a custom field in "Account" Object(Remaining Meetings). 
I need a trigger to roll up on Activities related to the Account object. 
All the openactivities(Count) of type "Meeting" should be counted and displayed "remaining Meetings" field.
 I have written a trigger on Tasks to count the no of open activities when a task is created and assigning the count value to the field in Account but the value is not updated.
 Can anyone help me with this??
 trigger UpdateAccount on Task (before insert) 
for(Task t : Trigger.new)
 {
 Account acc =[SELECT id,Annual_On_Site_Meetings__c,Actual_Meetings_Year_to_Date__c,(SELECT Status,WhatId from OpenActivities Where ActivityType Like 'Meeting') FROM Account where id=:t.WhatId];
 integer count = 0;
 for(OpenActivity oa:acc.OpenActivities)
 {
 count++;
 } 
System.Debug('-------Count'+count); 
acc.Annual_On_Site_Meetings__c=count; 
}
}
kranjankranjan
Hi Sindhu,

You have to also say update acc; in the last line.

Hope this helps.
sindhu@demo.comsindhu@demo.com
Hi kamal, Oops!!! Forgot...Thank you!! It worked
kranjankranjan
Gr8 Sindhu. You can accept the solution as answer if you liked it.... :)