Hi I want to create a dynamic query for each item in for loop , but again I don't want to execute that query in the for loop, right now since I am creating a query in for loop, I am no option but executing it in for loop, Is there any better way of doing it?

Any help is appreciated.Thanks!

  • Could you please elaborate your problem statement? You can create Map or Set or List in the loop and use that in the query outside the loop. – Kalpana Apr 27 at 8:02
  • Depends on the complexity of the query. If you used a map<string,object> you could store the elements of your query in your map, and use the object part to use a inner class to hold more of each query. The tricky part would be merging the say two different queries to the same sobject – Caspar Harmer Apr 27 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.