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
hylim1215hylim1215 

please help with my trigger "Too many SOQL queries: 101" error

Hi,

I have an after update trigger  like this
 
List<id> acc_ids = new List<id>();
 List<Account> acc_toUpdate = new List<Account>();



    if(trigger.isUpdate){
        
        for(Contact ctc:Trigger.new){
            Contact oldctc = trigger.oldMap.get(ctc.id);
  
             if(ctc.value__c != oldctc.value__c){
                    acc_ids.add(ctc.AccountId);  
              }
          }
      }

    if(acc_ids.size() > 0){
       // List<Account> acc = new List<Account>();
        for(Account acc: [Select id, CalculateALC__c from Account where id in: acc_ids]){
            acc.CalculateALC__c = true;
            acc_toUpdate.add(acc);
        }
    }
    
    if(acc_toUpdate.size() > 0){
        update acc_toUpdate;
    }

but i got error email from salesforce saying that Too many SOQL queries: 101 on this trigger when my user updating contact. Any thought?
 
Best Answer chosen by hylim1215
Lalit Mistry 21Lalit Mistry 21
I suspect the culprit for SOQL error is the trigger on account. Worth checking the trigger logic on account. You may want to post here if needed.

All Answers

Lalit Mistry 21Lalit Mistry 21
I suspect the culprit for SOQL error is the trigger on account. Worth checking the trigger logic on account. You may want to post here if needed.
This was selected as the best answer
EldonEldon
Hi
I tried it in my org and i am not getting any error and my account is getting updated. Please post the full code also try if there is any other trigger present on contact or account.
hylim1215hylim1215
yea right, it was the trigger on account. i already fix it.

thanks