You need to sign in to do that
Don't have an account?
Combination for multi select picklist using SOQL
From a visual force page, I return array of strings str[], which contains all the choices selected by the user through selectList with multi-"true". I have a multi-select picklist field in the object. I need to write a query that will return all the records from the object which matches wide variety of criteria. Here is an example:
There are five records in the object with values in the multi-select picklist as shown:
Type
Car
Car, Van
Car, Van, Jeep
Jeep
Jeep, Car, Bike
User selection in the str[] is {Car, Van, Jeep, Bike}
I want a SOQL query with filter on Type field which will return all the recrods from that object.
[select Name from someObject where Type includes (??)];
I would be very grateful if somebody can come up with solution.
Right now with my query all I am getting is records which have only single value picked.
Hi,
You can make run time query, plz refer code given below :
Suppose you have list having values from multiselect picklist named myValues.
List<String> myValues=new List<String>{'Car','Van','Jeep','Bike'};
String values='';
for(String s:myValues){
values+='\''+s+'\''+',';
}
String query='select name from someobject where Type includes ('+values.subString(0,values.length()-1)+')';
Database.query(query);
All Answers
Hi,
You can make run time query, plz refer code given below :
Suppose you have list having values from multiselect picklist named myValues.
List<String> myValues=new List<String>{'Car','Van','Jeep','Bike'};
String values='';
for(String s:myValues){
values+='\''+s+'\''+',';
}
String query='select name from someobject where Type includes ('+values.subString(0,values.length()-1)+')';
Database.query(query);
Thank you Alok. My mistake was I was concatinating them without surrounding individual item in the list within single quotes.