apex – SOQL Query in loop

apex – SOQL Query in loop

Where did you read that using Dynamic SOQL will result in data loss in this scenario? This is untrue AFAIK. The static Database.query() method behaves exactly the same as static SOQL, except for a few small differences.

To answer your first question, the main difference between your approaches is that the first is static (the query is fixed), and the second allows you to dynamically define the query, as the name suggests. Using your second approach with Dynamic SOQL will still chunk the result records for you.

This difference does lead to some other subtle considerations – Dynamic SOQL doesnt support variable bindings other than basic operations. See Daniel Ballingers idea for this feature here. I also need to add the necessary security caveat – if youre using Dynamic SOQL, do not construct the query based on input, as that would render your application vulnerable to SOQL injection.

Also, Im just curious, what is your use case/how large of quantities of data are you talking about here? It might be better to use batch Apex, depending on your requirement.

apex – SOQL Query in loop

Leave a Reply

Your email address will not be published. Required fields are marked *