You need to sign in to do that
Don't have an account?
Abhra 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.
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.
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
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.
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
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.
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!!
then try for update and after updating you opportunity, you can enable you triggers associated with opportunity.
So I can remove all the unwanted test class and make less number of test classes so I can reduce the execution