[SalesForce] Is LIKE Against a List Not Supported in Dynamic SOQL

I'm trying to use LIKE in my dynamic SOQL with a list.

My code:

SELECT Id, Name FROM Account WHERE Name LIKE ('%somevalue%', '%testvalue%')

I can't and I don't want to use variable reference for the list so I constructed this string.

The error when I try to run the above query:

expecting a colon, found '('

And When I add a colon this is the error that I get:

System.QueryException: Only variable references are allowed in dynamic
SOQL/SOSL.

How can I achieve this without using a variable reference?

The only other way I could think of is:

SELECT Id, Name FROM Account WHERE Name LIKE '%somevalue%' OR Name LIKE '%testvalue%'

With the above way, there's chance of hitting query string character limit.
Is there a better way to do this?

Best Answer

You can create a list of String with all the words in it. Then you can pass it in dynamic SOQL as well like you pass in normal SOQL query. That would work.

Below is the sample code:

List<String> s = new List<String>{'Burlington%','%plc'};
String query = 'select id, name from Account where name like :s'; 
List<Account> a = Database.query(query);