Tag Archives: Set

Use Like With List And Set Collections In SOQL Queries

Set Collection in Like:

Set<String> accountNames = new Set<String>{'%Sam%', '%App%', '%Len%','%Nok%'};
List<Account> accList = [Select Id, Name From Account Where Name LIKE :accountNames];

List Collection in Like:

List<String> accountNameList = new List<String>{'%Sam%', '%App%', '%Len%','%Nok%'};
List<Account> accList = [Select Id, Name From Account Where Name LIKE :accountNameList];

Convert List to Set in Salesforce

Sample Code:

//List of string variable
List<String> objList = new List<String>();
//Set of string variable
Set<String> objSet = new Set<String>();

objList.add('A');
objList.add('B');
objList.add('C');  

//Use addAll() to add list of string to Set
objSet.addAll(objList);

//Or Use Set Constructor
Set<String> objSetData = new Set<String>(objList);