-2

I have a dynamic soql in where I pass a string of ids in the WHERE IN clause this thtrows me a error:

expecting a colon, found '{'

My where clause is as follows:

WHERE Id IN {x0x0o000000000xXXX}

I also tried

WHERE Id IN :{x0x0o000000000xXXX}

I also tried adding {x0x0o000000000xXXX} to a string and do

WHERE IN :String 

this gives the error:

IN operator must be used with an iterable expression

So is it not possible to use a string in the SOQL itself and does it has to be :Set or :List?

I get the use of :Set my question is: is it in any way possible to use a string directly in de dynamic soql so use

testString = String.valueOf(Set<id>); 
WHERE IN testString
3
  • 1
    I literally spent 30 secondes to find this : salesforce.stackexchange.com/questions/17695/… Commented Jan 9, 2020 at 10:07
  • @MartinLezer I get the use of :Set<id> my question is: is it in any way possible to use a string directly in de dynamic soql so use testString = String.valueOf(Set<id>); WHERE IN testString
    – Thomas
    Commented Jan 9, 2020 at 10:12
  • @RohitMourya I get the use of :Set<id> my question is: is it in any way possible to use a string directly in de dynamic soql so use testString = String.valueOf(Set<id>); WHERE IN testString
    – Thomas
    Commented Jan 9, 2020 at 10:18

1 Answer 1

2

I think, that Rohit's comment serves the right link to get an answer, just some adjusting needed, however, here is the actual code you need:

You have:

Set<Id> ids = new Set<Id>{...};

You need to convert set to String:

String idsString = String.join(new List<Id>(ids), '\',\'');

Then you just need to make a query with such where-clause:

String whereClause = 'WHERE Id IN (\'' + idsString + '\')';

Not the answer you're looking for? Browse other questions tagged .