You need to sign in to do that
Don't have an account?
Megan Hairston 7
Apex Trigger Limit Exceeded for Opportunity Trigger
Error:Apex trigger OpportunityTrigger caused an unexpected exception, contact your administrator: OpportunityTrigger: System.LimitException: Too many SOQL queries: 101
Opportunity Trigger:
trigger OpportunityTrigger on Opportunity (before update, after update)
{
if(GenericServices.getGeneralSettingValueForKey(Constants.OPPORTUNITY_TRIGGER_KEY) == '1')
{
if(Trigger.isBefore)
{
OpportunityServices.copyChangeOrderOLIsToParentOpportunity(Trigger.newMap, Trigger.oldMap);
OpportunityServices.updateChildAssetsWithDataFromOpenAir(Trigger.newMap, Trigger.oldMap);
}
else
{
OpportunityServices.createUpdateAssets(Trigger.newMap, Trigger.oldMap);
}
}
}
As a brand new SFDC Admin, I am having a hard time knowing why just this one opportunity is causing the error. Any thoughts?
Opportunity Trigger:
trigger OpportunityTrigger on Opportunity (before update, after update)
{
if(GenericServices.getGeneralSettingValueForKey(Constants.OPPORTUNITY_TRIGGER_KEY) == '1')
{
if(Trigger.isBefore)
{
OpportunityServices.copyChangeOrderOLIsToParentOpportunity(Trigger.newMap, Trigger.oldMap);
OpportunityServices.updateChildAssetsWithDataFromOpenAir(Trigger.newMap, Trigger.oldMap);
}
else
{
OpportunityServices.createUpdateAssets(Trigger.newMap, Trigger.oldMap);
}
}
}
As a brand new SFDC Admin, I am having a hard time knowing why just this one opportunity is causing the error. Any thoughts?
Check for the methods and see where you have SOQL inside for loop. Code should be bulkified.
Regards,
Mahesh
1) http://help.salesforce.com/apex/HTViewSolution?id=000181404&language=en_US
2) https://help.salesforce.com/apex/HTViewSolution?id=000213152&language=en_US
Here are some best practices that will stop the error messages and/or help you avoid hitting the Governors Limit:
1. Since Apex runs on a Multitenant structure, Apex runtime engine strictly enforces limits to ensure code doesn't monopolize shared resources. Learn about the Governors Limit.
2. Avoid SOQL queries that are inside FOR loop.
3. Check out the Salesforce Developer Blog where you can find Best Practices for Triggers.
4. Review best practices for Trigger and Bulk requests on our Force.com Apex Code Developer's Guide.
5. Be sure you're following the key coding principals for Apex Code in our Developer's Guide.
Let us know if this will help you
Thanks
Amit Chaudhary