1

I have sets of objects CustomObjectA, CustomObjectB, CustomObjectC... that I need to pass to a method.

I would like to put them in a Map of type Map< String, Set< sObject > >, but when I try, I get an error:

Incompatible types since an instance of Set<CustomObjectA> is never an instance of Set<sObject>.

Incompatible types since an instance of Set<CustomObjectB> is never an instance of Set<sObject>.

When I change it to lists instead of a sets (using Map<String, List<sObject>>) and lists of my custom objects, I don't encounter the same problem.

Why would that occur?

2

I explained a bit in this question that collection type casting is broken. You can't use Set<ConcreteSObjectType> if you want to be dynamic, so you'll have to settle for adding the records directly to a Set<SObject> instead.

| improve this answer | |

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