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
HanumanthuHanumanthu 

Too many SOQL Queries 101 on triggers

Hi All,

       In My org Opportunity Object Contains 20 Triggers. Each trigger contains 5 Queeries. Now I am trying to inserting the record.It shows the ERROR* like this " Too many SOQL Queries 101". The triggers all are fired and it reach the governer limit .So please help me how to resolve this situation.


Thanks&Regards
Hanu
Best Answer chosen by Hanumanthu
sachin_dreamoncloudsachin_dreamoncloud
Need to analyze your code.. 
Seperate all insert n update logic.
On update add condition to check if the specific value as changed
       for Expl: if you have any update logic which needs to be executed for specific value change
                       add condition like this 
                      if(trigger.new[0].SomeField__c != trigger.oldMap.get(trigger.new[0].id).SomeField__c){  //this checks if the value is changed for update
                                 code to be executed.......
                      }
Check out this link for stopping recursive trigger. you need to debug more n stop unnecessary execution. Unless looking at your code can't suggest the exact things to change.
Stopping recursive trigger (http://help.salesforce.com/apex/HTViewSolution?id=000133752&language=en_US)

All Answers

sachin_dreamoncloudsachin_dreamoncloud
Optimize your code..
1. Stop unnecessary firing of  triggers, add conditions and execute those part of code only if the specific criteria is met.
2. Check old and new values and execute only on change.
3. if there is any recursive firing use recursion helper class to set values after execution.
HanumanthuHanumanthu
Hi Sachin,

Thanks for replying. But when we are trying to Insert a new record the triggers which are existing on the object are firing multiple times due to which we are not able to save the record.

Pls suggest!!!!!!!!!!!!!!!!!!
sachin_dreamoncloudsachin_dreamoncloud
Need to analyze your code.. 
Seperate all insert n update logic.
On update add condition to check if the specific value as changed
       for Expl: if you have any update logic which needs to be executed for specific value change
                       add condition like this 
                      if(trigger.new[0].SomeField__c != trigger.oldMap.get(trigger.new[0].id).SomeField__c){  //this checks if the value is changed for update
                                 code to be executed.......
                      }
Check out this link for stopping recursive trigger. you need to debug more n stop unnecessary execution. Unless looking at your code can't suggest the exact things to change.
Stopping recursive trigger (http://help.salesforce.com/apex/HTViewSolution?id=000133752&language=en_US)
This was selected as the best answer