function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pavani Akella 9Pavani Akella 9 

How to avoid SOQL query exception

An installed package(Declarative Lookup Rollup summary) has an automated trigger. This trigger is resulting in throwing "dlrs_CaseTrigger: System.LimitException: dlrs:Too many SOQL queries: 101" error when Salesforce is receiving batch insert of cases. How do I move the trigger to not throw SOQL query exception.

trigger dlrs_CaseTrigger on Case
    (before delete, before insert, before update, after delete, after insert, after undelete, after update)
{
    dlrs.RollupService.triggerHandler();
}

Thanks in advance
Khan AnasKhan Anas (Salesforce Developers) 
Hi Pavani,

Greetings to you!

The following error appears when you exceed the Execution Governors Limit (you can run up to a total 100 SOQL queries in a single call or context). 

To fix this problem you have to take your SOQL out of the for loop.

Best practices to avoid exceeding the Governors Limit :
 
I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Khan Anas
Pavani Akella 9Pavani Akella 9
Thanks Khan for the response. Can you please help me write the code to take the SOQL out of the loop please. I'm new to development. Thanks in advance!
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Are you referring to this tool: https://github.com/afawcett/declarative-lookup-rollup-summaries

If yes, then for this tool 101 SOQL exception is very hard to track down. It might possible that you have a lot of child records related to parent records you are rolling up on. Or, you have too many rollups defined to one parent.

However, you can refer to below links which might help you.

https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/276

https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/629

https://andyinthecloud.com/2014/02/09/new-release-spring14-declarative-rollup-summary-tool/


Regards,
Khan Anas