function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Krishnan MishraKrishnan Mishra 

What is wrong in the following soql query?

id i = 0037F00000M6MCHQA3;
String fieldNames='name,id';
String objName = 'contact';
String queryStr = 'SELECT ' + fieldNames + ' FROM ' + objName + ' WHERE id IN :(\'i\')';
System.debug(queryStr);

 
Krishnan MishraKrishnan Mishra
Hi Alain, 
The result of your query is SELECT name,id FROM contact WHERE id IN :('0037F00000M6MCHQA3'), but i want to display the seleceted records.
Alain CabonAlain Cabon
The colon is useless here :
Id i = '0037F00000M6MCHQA3';
String fieldNames='name,id';
String objName = 'contact';
String queryStr = 'SELECT ' + fieldNames + ' FROM ' + objName + ' WHERE id IN (\'' + i + '\')';
System.debug(queryStr);