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
Megan Hairston 7Megan 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?
venkat-Dvenkat-D
The error will be in OpportunityServices class. 
Check for the methods and see where you have SOQL inside for loop. Code should be bulkified.
Mahesh DMahesh D
Please paste the OpportunityServices class here and it will be easy to identify the issue.

Regards,
Mahesh
Amit Chaudhary 8Amit Chaudhary 8
Please check below post how to resolve the issue
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