1

I have fixed set of Account Names stored in one custom object.

Set<String> NameSet = new Set<String>();

Custom object NameSet account Name values: Intel, HP, Dell, IBM etc

I have a query on Account object. My Account Names are Intel-Aus, HP, Dell-US, IBM etc

List<Account> accList = [Select Name from Account where Name IN: NameSet]

The above accList only gives 2 records HP and IBM!

Intel and Dell do not come in the list because these account names have "hyphen" in it.

How do I write the query to get all the Account Names using %Like% in a single query.

sfdcFanBoy
  • 4,064
  • 7
  • 43
  • 85

1 Answers1

2

You can do like this way

Create set of string %Name1%, %Name2%etc

List<String> lstString = new List<String>{`%Name1%`, `%Name2%`, `%Name3%`};
List<Account> accList = [Select Name from Account where Name LIKE: lstString ];

Updates

List<String> lstString = new List<String>{'%Intel%', '%HP%', '%Dell%' , '%IBM%'};

for(Account obj : [Select Name from Account where Name LIKE: lstString ]){
    system.debug(obj);
}

This will return all the Accounts with name Intel-Aus, HP, Dell-US, IBM.

enter image description here

Ratan Paul
  • 22,663
  • 13
  • 52
  • 97