How to avoid or reduce SOQLs in Salesforce?

1. Do not use SOQL inside the for loop.

2. User UserInfo wherever possible - http://www.infallibletechie.com/2016/01/how-to-get-username-of-user-using-apex.html.

3. Use Custom Settings for hard coding Report Folder or Dashboard Folder ids, Email Templates ids, Public Group ids, Field ids, etc.

4. Use @future methods or queueable interface.

http://www.infallibletechie.com/2012/08/future-annotation-in-salesforce.html

http://www.infallibletechie.com/2016/08/queueable-apex.html

5. Avoid triggers from firing again and again - http://www.infallibletechie.com/2014/05/how-to-avoid-recursive-trigger-in.html.

6. Use trigger instead of workflow rules and process builders since they are not bulkified.

7. Use schema instead of query to get record type, etc - http://www.infallibletechie.com/2014/03/how-to-get-recordtypeid-using-record.html.

Cheers!!!

No comments:

Post a Comment