Object acclist = new List<SObject>{new Account()};
System.debug(acclist instanceof List<SObject>);
System.debug(acclist instanceof SObject);
The code above prints true true
Is List<SObject>
a subtype of SObject
?
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityNo, 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.