1.Mixed DML Operation Error:
Reason: When you try to combine DML operations for both Setup and Non-Setup objects in a same transaction (Where Setup objects such as Group, Group member, Queue SObject, User. Non-Setup Objects such as Standard and Custom Objects).
Resolution: We can use @future annotation to do DML operation. It will split the transactions.
Another approach is to use same logic in a batch class to overcome.
2.Cpu time limit exceed:
Reason 1: Based on CPU usage, Salesforce has a timeout limit for each transaction. Due to consumption of too much CPU time limit in a transaction, this error could occur.
Reason 2: If you use nested for-loop (for-loop inside another for-loop), then you must use Map(s) to resolve the issue, as it is one of the common reasons for CPU Time Limit
For { for { } }
Counted:
- All Apex Code.
- Workflow execution.
- Library functions exposed in Apex.
Not Counted:
- Database Operations (DML)
- SOSL
- SOQL
- HTTP Callouts.
3.System.QueryException: Non-selective query against large object type:
Reason: If you query records on object that returns more than 200,000 records and without query filters, it’s possible that you’ll receive the error, “System.QueryException: Non-selective query against large object type.” We’ll go over the a few possible fixes.
Resolution: It’s best to try to have that field indexed by checking the “external ID” checkbox when you create that field. Also, as a best practice, always use WHERE clause in your SOQL statements to read the records.
Example: [Select id, Name, Type from Account WHERE Type = “Prospect”];
Finally, filter out all null records in your Apex query.
4.Too many SOQL Queries:
Reason: We can run up to a total of 100 SOQL queries in a single transaction or context. All the SOQL queries in triggers fired from one call or context will be counted against the limit of 100. When the number of SOQL queries exceed the limit in a single transaction, then this error is thrown by Salesforce.
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. Here are some best practices that will stop the error messages.
Governor Limit:
1. Since Apex runs on a multi-tenant platform, the Apex runtime engine strictly enforces limits to ensure code doesn’t monopolize shared resources. Learn about the Governor Limits
2. Avoid SOQL queries that are inside for loops.
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.
Important: Salesforce