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

Way to build queries with dynamic variables?

Hi All, 


I think this is probably impossible, but wanted to see if anyone had any genius ideas.... 



I want to build a query using all variables.  So for example, I would have an object var, a fields list var, an operator var, and a value var.  So it would look something like this in my head:


List<object>  myList  =  new List<object>([select fields list FROM object WHERE field operator value]); 




Any thoughts?  





Hi Stephen,

you can achieve this by using dynamic soql.

Please look at this article for more details: .

Also, you might find this library interesting to build Soql dynamically: .