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
ajay ambatiajay ambati 

exceptions

how to avoid more dml and soql queries operations in loop? give me exact answer for this?
JethaJetha
Please go through th Apex best practices :

https://developer.salesforce.com/page/Apex_Code_Best_Practices
sslodhi87sslodhi87
By using the collection classes like list and map you can avoid dml and soql 
DeepthiDeepthi (Salesforce Developers) 
Hi Ajay,

Placing the SOQL or DML statements with in a loop hits the governor limits as it iterates over the size of the list(usually collection).
An individual Apex request gets a maximum of 100 SOQL queries before exceeding that governor limit. So if any operation is invoked by a batch of more than 100 Account records, the governor limit will throw a runtime exception.
Usually, there is a limit of 150 DML operations per request, a governor limit will be exceeded after the 150th contact is updated.
Here is the optimal way to 'bulkify' the code to efficiently query the contacts in a single query and only perform a single update DML operation.

Please follow the links for more details:
https://developer.salesforce.com/page/Apex_Code_Best_Practices 

https://developer.salesforce.com/blogs/developer-relations/2015/01/apex-best-practices-15-apex-commandments.html 

https://developer.salesforce.com/page/Best_Practice:_Use_of_the_Limits_Apex_Methods_to_avoid_Hitting_Governor_Limits 

Hope this helps you!
Best Regards,
Deepthi