SFDC common errors

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值