• sastry.soft1.3935945807637227E12
  • NEWBIE
  • -4 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
difference between "Trigger.New" and "Trigger.old".

I found this trigger and made a couple changes to it in attempts to get a simple roll up count of activities in the Activity History of Accounts. 

 

trigger Activity_Count_2 on Task (after insert, after update, after delete, after undelete) {
List<Account> uplist=new List<Account>();
List<Account> lelist=[select id,Activity_Count_2__c from Account];
List<AggregateResult> st=new List<AggregateResult>();
st=[select count(Id),whoid from task where id=:Trigger.new and status='Completed' group by whoid];
for(Integer i=0;i<st.size();i++)
{
for(Account a:lelist)
{
if(a.id==st[i].get('whoid'))
{
a.Activity_Count_2__c=(Integer)st[i].get('expr0')+a.Activity_Count_2__c;
uplist.add(a);
}
}
}
update uplist;
}

 

Unfortunately, when I went to log an activity at the Account I received this error:

 

"Apex trigger Activity_Count_2 caused an unexpected exception, contact your administrator: Activity_Count_2: System.LimitException: Too many query rows: 50001"

 

 

What am I missing here?