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
Sfdc SivaSfdc Siva 

Too many SOQL queries: 201 From Batch

Hi All,

Can any one help me to avoid 201 SOQL Error When we are running the batch getting the error.Please help me to avoid this.


Thanks
NagendraNagendra (Salesforce Developers) 
Hi Siva,

This error usually means a larger issue with your code scalability in general.

If you want the easy fix though, change the batch size to 1 when you create your batch.  Sorta like this:

Database.executeBatch(sObject batchName, 1)

You should never have SOQL queries inside loops. Fix that one and look for other occurrences, that is very much likely to be the cause of your Exception. The alternative is to make that query outside of a loop only once, and you can make a Map<Id, SObject> to map the queried objects and be able to access them inside the loop later, instead of making the query there.

Hope this helps.

Please mark this as solved if it's resolved so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra
Sfdc SivaSfdc Siva
Hi Nagendra,

1.I have tried  database.executeBatch(btch,1),but still getting error.
2.And also we are using Map<Id, SObject> some usecases.

Can you please post me your personal email id.So that i will share my batch apex.

Thanks