3
Object acclist = new List<SObject>{new Account()};
System.debug(acclist instanceof List<SObject>);
System.debug(acclist instanceof SObject);

The code above prints true true

print

Is List<SObject> a subtype of SObject ?

1 Answer 1

7

No, SObject is not a subtype of List<Sobject>. This is a quirk in the language, likely related to the fact that you can assign the results of a query to a single variable:

sobject record = [select name from account limit 1];

This only works with queries (including database.query, etc), and only if there's exactly one row returned. In no other sense does this work. If you're doing dynamic data checks, check if the variable is a list first, and if not, then if it's a single sobject.

You must log in to answer this question.

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