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
Colin LoretzColin Loretz 

Query string in Apex

I have a need to generate a dynamic query string for a SOQL query but the statement won't accept a string for a query.


string qstring = "select Id, Field from Object where x = 'y' or x = 'z' and z = 'x' or z = 'y'";

List<Object> objects = new List<Object>(qstring);

Is there a way to do this? I need to build the query string because, based on a multiselect field, there could be anywhere from 1 to 10 OR statements for each field
EJWEJW
Dynamic SOQL will do what you want to do but it's only available as a developer preview with Summer '08.  Not sure how to get it enabled for your org, I'd try contacting support.