0
trigger SoM_RequestCancelledOnFeePayment on SoM_Request__c (after update) {
    if (!SoM_Utilities.gs.Disable_Triggers__c) {
        List<MUSW__Fee_Payment__c> feePymtsToUpdate = new List<MUSW__Fee_Payment__c>();
        List<MUSW__Fee_Payment__c> fpList = [SELECT Id, Name, CreatedDate, SoM_License__r.MUSW__Type__c, SoM_Request__r.SoM_Status__c 
                                             FROM MUSW__Fee_Payment__c 
                                             WHERE SoM_Request__c IN :Trigger.OldMap.KeySet() AND SoM_Request__r.SoM_Status__c = 'Cancelled' AND SoM_License__r.MUSW__Type__c = 'Special 24-hr License'];
        //system.debug(JSON.Serialize(fpList));
        for(MUSW__Fee_Payment__c fp : fpList){
            if(fp.SoM_License__r.MUSW__Type__c == 'Special 24-hr License' 
               && fp.SoM_Request__r.SoM_Status__c == 'Cancelled'){
                   fp.Request_Cancelled__c = True;
               }
            feePymtsToUpdate.add(fp);
        }
        if(feePymtsToUpdate.size()>0){
            Update feePymtsToUpdate;
            //System.debug('Fee Payments to Update: '+feePymtsToUpdate);
        }
    }
}

There's no Query or DML involved in the FOR loop yet i am getting Too many SOQL queries: 101 error. fpList is at Line 12

enter image description here

Could someone help me understand what else would result to this issue. There are multiple triggers on the same object and multiple triggers on other objects as well which is querying SoM_Request__c object. i am working on a trigger pattern right now to avoid multiple triggers but is that something that could be a possible root cause for this issue?

2
  • It is quite easy to end up in an infinite cycle when a trigger updates an other object and the other objects then update the original object. – Keith C Nov 30 '18 at 17:23
  • you hit the error when All the SOQL queries in triggers fired from one call or context will be counted against the limit of 100 are exceeded, so you will have to look at all the queries in the different triggers on the same object as well as any subsequent objects and their triggers getting called in your current context! – codeyinthecloud Nov 30 '18 at 17:23
3

This is a typical scenario where the wrong code is being "blamed" for having incorrect behavior. You'll need to check your debug logs for other triggers or process builder actions that may be causing this. Remember that the SOQL limit is a cumulative limit, so if one trigger uses 99 queries, and one uses 2, the one that used just 2 can be blamed despite not actually being the problem.

2
  • Thank you. I am seeing many triggers being called in the debug log. Is there a good way to identify the culprit ? Been stuck with this for awhile now :| – SunnyG Nov 30 '18 at 17:51
  • @SunnyG Turn on a debug log and set "profiling" up to "finest"; your logs will show which queries are being called most frequently. – sfdcfox Nov 30 '18 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.