Why Set doesn’t support DML operation

As we know that set<Sobject> and list<Sobject> are collection type.

So basic question I do have why Set doesn’t support DML operation ?

We can perform DML on List<Sobject> but why not on set<Sobject>

Any idea?


One reason may be that Set<SObject> is a risky mechanism to use: equality is based on all the fields (so is expensive) and if fields are changed logic can easily break. Same problem using SObject as a Map key. So not a pattern to be encouraged.

But perhaps just because also supporting Set<SObject> adds a bunch of extra methods that need documenting and supporting. (Given that there isn’t any common superclass.) And the conversion to list is trivial:

Set<SObject> s = ...;
someDmlOperation(new List<SObject>(s));

Source : Link , Question Author : Ratan Paul , Answer Author : Keith C

Leave a Comment