I have some dynamic SOQL code in which I'd like to identify whether a method argument is a collection or a single value:
SObject[] query(SObjectType sobType, String field, Object data) {
// Want to know if data is a collection e.g. set or list
// that requires an "in" or a single value that requires
// an "=" in the query. (May also need to use separate bind variables.)
}
I note that the sort of check shown immediately below seems to require an exact match for the type of the collection (Id
in this case to return true) which is not what I want:
Object o = new Set<Id>();
System.debug(o instanceof Set<Id>);
Is there a simple way to make this determination?
(Yes there are various other ways to code this; checking first to see if there is a direct solution.)
PS
Looks like great caution is needed when using instanceof with collections.