Mixed DML Operation Error -
What's the Reason?
If we combine DML operations for both Setup ( Group, Group member, Queue SObject, User) and Non-Setup objects(Standard and Custom Objects) with in same transaction .
What's the Resolution?
Also, we can use same logic in a batch class to get rid of the issue.
For more Info - https://help.salesforce.com/articleView?id=000315345&type=1&mode=1
Too many SOQL Queries –
What's the reason?
This appears when you exceed the Execution Governors Limit (you can run up to a total 100 SOQL queries in a single call / context).
System.LimitException: Too many SOQL queries: 101 error
Please note:
- All the SOQL queries in triggers fired from one call or context will be counted against the limit of 100.
- Remember, Salesforce cannot disable or raise the Governors Limit.
What's the Resolution?
To fix this issue, you’ll need to change your code in such a way that the number of 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.
Best practices to avoid exceeding the Governors Limit
Apex runs on a multi-tenant platform; the Apex runtime engine strictly enforces limits to ensure code doesn't monopolize shared resources.
Thus,
- Avoid SOQL queries that are inside FOR loops.
- Follow the key coding principals for Apex Code in Salesforce Developer's Guide(https://developer.salesforce.com/wiki/apex_code_best_practices).
- Verify Salesforce best practices for Trigger and Bulk requests(https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_bestpract.htm)
For Best practices for Triggers and Bulk requests (Refer - Force.com Apex Code Developer's Guide)
Reference(s) - https://help.salesforce.com/
Comments
Post a Comment