+ Start a Discussion
Abhra PalitAbhra Palit 

22 Active triggers in Opportunity. 101 SOQL error for any update

Hi,

The CRM I am working has 22 Active triggers in Opportunity Object. Every time I am trying to update any thing related to Opportunity, it is giving me 101 SOQL error. Even when I deploying Class,testClass in production is giving same error.

Any idea how to deal with this situation.
Ivaylo BalabanovIvaylo Balabanov
Hello,

Please provide the code or maybe it is going to be difficult with so many triggers.
Check if you have SOQL in a loop.

Reagrds,
Ivo
Anoop yadavAnoop yadav
Hi,

Please chek the below link for trigger best practice.
https://developer.salesforce.com/page/Apex_Code_Best_Practices

You should not create more than one trigger per object.
Create a Trigger Handler class and paste the code there and call the Class method from trigger.
Abhra PalitAbhra Palit

Thanks Anoop. I will try the trigger handler class.

Thanks Ivaylo. I have all ready checked all the trigger for SOQL inside for loop. Its been removed

Sudeep DubeSudeep Dube
Your Active trigger cross governor limit for SOQl it may be recursive trigger any where . are tesing is not proper for all the valid and invalid data
lifewithryanlifewithryan
Along the lines of the recursive trigger mentioned above. You should try to check whether or not a trigger has already run for a given object by using a static variable in a utility class to  determine whether or not the current ID has already been processed by a given trigger:

public class MyTriggerUtil {
   public static Set<ID> processedIds = new Set<ID>();

   public static Boolean isProcessed(ID id)  {
       if(processedIDs.contains(id) {
           return true;
       } else {
           processedIds.add(id);
           return false;
       }
   }
}

Then in your trigger, check MyTriggerUtil.isProcessed before doing anything with it.
lkatneylkatney
Hey,

You need to check for few things:
1. Check for SOQL queries in loops and  move them out from loops.
2. Your trigger should not run unnecessarily on each DML operation. It should have check for value changes and then execute your code. This will stop your recursive runs of your triggers.
3. Above can also be achived by adding a static variable and set it once your trigger is executed.

Hope this helps!!

Ravi NarayananRavi Narayanan
try to remove if you used any queries for recordtype.  use schema methods instead., 
umesh atryumesh atry
Hi , Just Disable All Trgigger which associated to Opportunity.
then try for update and after updating you opportunity, you can enable you triggers associated with opportunity.
Abhra PalitAbhra Palit
Thanks Guys.... I am trying all possible ways to solve the prob...can anyone assist me the steps to make a package for all test classes involved in making the 101 SOQL error.
So I can remove all the unwanted test class and make less number of test classes so I can reduce the execution