I'm trying to cast a Map<Object, SObject>List<SObject>>
to Map<String, Account>List<Account>>
, which fails with the error
Incompatible types since an instance of
Map<Object,SObject>
is never an instance ofMap<String,Account>
That's because Apex likely gets transpiled to Java where Map is a compile-time abstraction. Unlike Java, we can't force the issue by writing something like
Map<Object, SObject>List<SObject>> foo = ... // some initialization
Map<String, Account>List<Account>> bar = (Map) foo;
because raw Map
doesn't exist in Apex. Can this be worked around somehow? The end goal is to have a Map<Object, SObject>List<SObject>>
return type which would allow a method to return maps of various types of SObject
s.