You need to sign in to do that
Don't have an account?

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

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.