You need to sign in to do that
Don't have an account?
System.LimitException: Too many SOQL queries: 101
Hi,
I am getting an error on a trigger .
I am posting the trigger here
Can someone help me please.
trigger rollupreferred3OpenAct on Account (before insert, before update) {
if(trigger.isinsert) {
for( Account ac:trigger.new)
ac.Open_Actitvities_By_Referred_3__c = 0;
}
else
if(trigger.isupdate) {
for( Account aci:trigger.new)
for(Account ac : [select a.id, a.Referred_To_3__c, ( Select t.id from Tasks t where ( t.status != 'Completed' ) and ( t.ActivityDate >= Today )
and ( t.OwnerId =: aci.Referred_To_3__c )) from Account a where a.id in :trigger.new])
trigger.newmap.get(ac.id).Open_Actitvities_By_Referred_3__c = ac.Tasks.size();
}
}
Can you please help me in doing that.
Thanks
Instead of looping through each one and executing a SOQL, you'll want to build a unique set through the loop and execute one query with an IN clause. Something like this:
SOQL / DML in loops should be avoided as much as possible.