How to avoid or reduce SOQLs in Salesforce?

How to avoid or reduce SOQLs in Salesforce?

1. Do not use SOQL inside the for a loop.

2. User UserInfo wherever possible – https://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.

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

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

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

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

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

Leave a Reply