I have a dynamic Soql in which I want to pass a set.
I get an error:
System.QueryException: expecting a colon, found '{'
Anonymous window
Set<Id> idSet = new Set<Id> ();
idSet.add('xxxxx00000xxxxAAAR');
RS.GetOrder('xxxxx00000xxxxAAAR', idSet);
Class
public class RS {
..
public static LIST<Order__c> GetOrder(string idField, Set<Id> idSet) {
..
String where_clause = '';
if (idField != null && idSet == null) { where_clause = ' WHERE Id =\'' + idField + '\'';
}
String where_in_clause = '';
if (idField != null && idSet != null) { where_in_clause = ' WHERE ' + idField + ' IN ' + idSet;
}
String soqlSo = 'SELECT' + cFieldsSo ' FROM order__c' + where_clause + where_in_clause;
system.debug('soqlSo: ' + soqlSo);
List<sObject> sobjSoList = Database.query(soqlSo);
}
Debug
...FROM Staging_order__c WHERE xxxxx00000xxxxAAAR IN {a1x2o00000xxxxAAAR}
When I add a colon
where_in_clause = ' WHERE ' + idField + ' IN :' + idSet;
I get the error
System.QueryException: unexpected token: '{'