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
StephenJacobGoldbergStephenJacobGoldberg 

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?  

 

 

 

sebcossebcos

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/ .