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
Jitender  PaddaJitender Padda 

Need some Experts advice

Hi All,

I am writing some complex code for an existing application and that code will be merged into a managed package. Due to the complexity of the project , I have to Query and use DMLs inside a loop. I tried a lot to avoid it but it seems to be the only way. I just want to know if it will pass the security review? It is being used by a Batch Class and the Batch size is fixed from code so error will never come up, but will salesforce allow this ?? Please give me your suggestions.
Best Answer chosen by Jitender Padda
PratikPratik (Salesforce Developers) 
Hi Jitender,

As per the Salesforce best practices, the DML operations should be carried out of the loop to avoid the Governor limits. To make dml operations out of loop is to avoid hitting the governor limits and bulkify the code. If your dml operations are inside loop and if you can test your code for bulk operations without any failure then you are good to go. 

Thanks,
Pratik

All Answers

PratikPratik (Salesforce Developers) 
Hi Jitender,

As per the Salesforce best practices, the DML operations should be carried out of the loop to avoid the Governor limits. To make dml operations out of loop is to avoid hitting the governor limits and bulkify the code. If your dml operations are inside loop and if you can test your code for bulk operations without any failure then you are good to go. 

Thanks,
Pratik
This was selected as the best answer
PratikPratik (Salesforce Developers) 
Glad it helped!

Thanks,
Pratik