+ 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:

http://blog.sforce.com/sforce/2008/09/dynamic-soql--.html .

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

http://richardvanhook.com/2010/04/11/soql-builder/ .