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
FinneyFinney 

System exception : Too many SOQL queries: 101

Hi,

 

I have written a trigger on the agreement object to close the cases related to the agreement.

 

When I am doing any other update on the agreement, the trigger is throwing the error

 

Too many SOQL queries.

 

It used to work good until today. I don't know the reason for this error.

 

please find the trigger here

 

trigger CloseCase on pb__Agreement__c (before update) {
//List<ID> accIds = New List<ID>();
List<ID> agIds =New List<ID> ();
for(pb__Agreement__c ag:Trigger.new){
if(ag.pb__AgreementType__c == 'Sale' && ag.Stage__c == 'Transaction Closed'){
agIds.add(ag.Id);
}
}
List<Case> c = [ SELECT id,Agreement__c,Status, RecordTypeId from Case where Agreement__c = :agIds and RecordTypeId = '012A0000457547' LIMIT 2];
if(c.size() > 0){
Case cs = c[0];
c[0].Status = 'Closed';

}
update c;
}

 

 

Please help me.

 

Thanks and Kind Regards

 

Finney

VVKrishnaVVKrishna

Do you have only one trigger on Agreement Object? If not can you check if there are any SOQL statements written in For loop in those triggers

FinneyFinney

I have a few more but this is the trigger that is the cause of the error.

 

 

VVKrishnaVVKrishna

Can you please check if those triggers are having any SOQL statements in for loop or if you are updating the Agreement record through any custom page, check the apex class of that page if it is having any SOQL's in for loop

ra1ra1

May be there are few triggers on "Case" object which are causing this issue.

 

I also found that you are changing status of one case record (i.e. c[0] )  but updating both two records. which is also wrong.

 

Last I would suggset to comment "update c;" line and check if you are getting error or not. If you are not getting any error, then "Too many SOQL queries" error is due to your Case triggers.

 

Thanks