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 ?

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.