You need to sign in to do that
Don't have an account?

Error in Too many soql 101
Hi All
How to overcome salesforce limitation System.LimitException: Too many SOQL queries: 101
How to overcome salesforce limitation System.LimitException: Too many SOQL queries: 101
List<MasterCopy__c> masterCopyList = new List<MasterCopy__c>([Select Name,DateUpdate__c, Opening_Balance__c, Closing_Balance__c, Master_Code__c, Master_Name__c from MasterCopy__c]); List<MasterCopy__c> upsertMasterList = new List<MasterCopy__c>(); MasterCopy__c masterCopyInsert; List<MasterTest__c> masterTestList = new List<MasterTest__c>([Select Date__c, Opening_Balance__c, Master_Code__c, Name, Closing_Balance__c from MasterTest__c]); if(trigger.isBefore && trigger.isInsert ){ for(MasterTest__c masterTest : trigger.new){ masterTest.EntryDate__c = masterTest.Date__c; masterTest.To_Date__c = masterTest.Date__c; masterTest.From_Date__c = masterTest.Date__c; masterTest.Closing_Balance__c = masterTest.Opening_Balance__c; } }
See This code :
if(trigger.isBefore && trigger.isInsert ){
for(MasterTest__c masterTest : trigger.new){
masterTest.EntryDate__c = masterTest.Date__c;
masterTest.To_Date__c = masterTest.Date__c;
masterTest.From_Date__c = masterTest.Date__c;
masterTest.Closing_Balance__c = masterTest.Opening_Balance__c;
}
}
Note : Here you are not passing any Soql in this trigger code . So how are you getting this Error Too many SOQL queries: 101
Please Share Full code
The "System.LimitException: Too many SOQL queries: 101" error appears when you've hit the Execution Governors limit, which means you can run a total 100 SOQL queries in a context. All the triggers fired will be counted in a single context or call. To fix the issue, you'll need to change your code in such a way that SOQL fired is less than 100. If you need to change the context then you can use @future annotation which will run the code asynchronously.
The error is fired at line number 2 because you are using a list(collection) data type and writing the SOQL to fetch the details.List datatype can contain multiple records.Please make sure what's the amount of data you are fetching in the SOQL.It should not fire more than 100.
How to handle the above error:
- 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.
- Avoid SOQL queries that are inside FOR loop.
- Check out the Salesforce Developer Blog where you can find Best Practices for Triggers.
- Review best practices for Trigger and Bulk requests on our Force.com Apex Code Developer's Guide.
- Be sure you're following the key coding principals for Apex Code in our Developer's Guide.
Note : Salesforce cannot stop the Governors Limit or raise it. Following the best practices above should ensure that you don't hit this limit in the future.Please let us know if this helps you.
Best Regards,
Nagendra.P
By looking at logs, you can come to know which are all triggers being invoked in the execution flow and from there you can know if there is recursion(same trigger getting called multiple times).
Then a solution can be derived. I suggest you first check DEBUG LOGS.
- Harsha