Skip to main content
added 30 characters in body; edited title
Source Link
ipavlic
  • 3.8k
  • 7
  • 34
  • 56

Map<Object, SObject>List<SObject>> cannot be cast to Map<String, Account>List<Account>>

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 of Map<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 SObjects.

Map<Object, SObject> cannot be cast to Map<String, Account>

I'm trying to cast a Map<Object, SObject> to Map<String, Account>, which fails with the error

Incompatible types since an instance of Map<Object,SObject> is never an instance of Map<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> foo = ... // some initialization
Map<String, 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> return type which would allow a method to return maps of various types of SObjects.

Map<Object, List<SObject>> cannot be cast to Map<String, List<Account>>

I'm trying to cast a Map<Object, List<SObject>> to Map<String, List<Account>>, which fails with the error

Incompatible types since an instance of Map<Object,SObject> is never an instance of Map<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, List<SObject>> foo = ... // some initialization
Map<String, 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, List<SObject>> return type which would allow a method to return maps of various types of SObjects.

deleted 12 characters in body
Source Link
ipavlic
  • 3.8k
  • 7
  • 34
  • 56

I'm trying to cast a Map<Object, SObject> to Map<String, Account>, which fails with the error

Incompatible types since an instance of Map<Object,List<SObject>>SObject> is never an instance of Map<String,List<Account>>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> foo = ... // some initialization
Map<String, 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> return type which would allow a method to return maps of various types of SObjects.

I'm trying to cast a Map<Object, SObject> to Map<String, Account>, which fails with the error

Incompatible types since an instance of Map<Object,List<SObject>> is never an instance of Map<String,List<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> foo = ... // some initialization
Map<String, 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> return type which would allow a method to return maps of various types of SObjects.

I'm trying to cast a Map<Object, SObject> to Map<String, Account>, which fails with the error

Incompatible types since an instance of Map<Object,SObject> is never an instance of Map<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> foo = ... // some initialization
Map<String, 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> return type which would allow a method to return maps of various types of SObjects.

added 4 characters in body
Source Link
Adrian Larson
  • 151.4k
  • 38
  • 247
  • 431

I'm trying to cast a Map<Object, SObject> to Map<String, Account>, which fails with the error

Incompatible types since an instance of Map<Object,List>Map<Object,List<SObject>> is never an instance of Map<String,List>Map<String,List<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> foo = ... // some initialization
Map<String, 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> return type which would allow a method to return maps of various types of SObjects.

I'm trying to cast a Map<Object, SObject> to Map<String, Account>, which fails with the error

Incompatible types since an instance of Map<Object,List> is never an instance of Map<String,List>

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> foo = ... // some initialization
Map<String, 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> return type which would allow a method to return maps of various types of SObjects.

I'm trying to cast a Map<Object, SObject> to Map<String, Account>, which fails with the error

Incompatible types since an instance of Map<Object,List<SObject>> is never an instance of Map<String,List<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> foo = ... // some initialization
Map<String, 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> return type which would allow a method to return maps of various types of SObjects.

Source Link
ipavlic
  • 3.8k
  • 7
  • 34
  • 56
Loading