Hello I'm trying to use string in SOQL query where clause for multiselect picklist.
I need to get records of CustObj__c where Multipicklist__c fild have 'abc' or 'xyz' values.
String str = '\'abc\',\'xyz\'';
for(CustObj__c cust : [Select Id, Name, Multipicklist__c FROM CustObj__c WHERE Multipicklist INCLUDES (:str)]{
somelogic
}
However I get no records. What is wrong in this query?
Ok I tried using list too, here I'm getting all record of all Public Groups where user is assign. and saving those Public Groups names in
List<String> groupIds = new List<String>();
List<String> groupNames = new List<String>();
for(GroupMember gm :[SELECT Id,GroupId,UserOrGroupId FROM GroupMember WHERE UserOrGroupId = :userIds[0]]){
groupIds.add(gm.GroupId);
}
for(Group g :[SELECT ID,Name FROM Group WHERE Id IN :groupIds]){
groupNames.add('\'' + g.Name + '\'');
}
for(CustObj__c cust : [Select Id, Name, Multipicklist__c FROM CustObj__c WHERE Multipicklist INCLUDES (:groupNames)]){
somelogic
}
It still not working
I get error in Dev console : Invalid bind expression type of List for column of type String
INCLUDES ('abc', 'xyz')
. Or declare aList<String> selections = new List<String> { 'abc', 'xyz' };
thenINCLUDES :selections
, but I don't have any multi-select picklists to test against.'\'
in the linegroupNames.add('\'' + g.Name + '\'');
? Also, you're doing a query in a loop. Please consider taking that out.INCLUDES
EXCLUDES ('123')
for the negative case where you want all but a few values. developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/…