System.QueryException: Invalid bind expression type of X for column of type Id
Posted: 2026-02-27
This piece of code:
bindMap.put('idList', excludeIds);
whereClause += (hasWhere ? ' and ' : ' where ') + ' Id NOT IN (:idList) ';
was generating this exception:
System.QueryException: Invalid bind expression type of Set
for column of type Id
Which seemed... odd. excludeIds is declared as having type Set<Id> so why the error? After trying several variations of lists and sets, and casting before putting the value into the map to be doubly sure of it's type, I found the solution, remove the parentheses:
bindMap.put('idList', excludeIds);
whereClause += (hasWhere ? ' and ' : ' where ') + ' Id NOT IN :idList ';
Job done.