Activity › Forums › Salesforce® Discussions › Why we cannot perform DML operation on SET type collection variable in Salesforce?
Tagged: Collection Variable in Salesforce, DML Exception, DML Operations, DML Statement, Salesforce exceptions
-
Why we cannot perform DML operation on SET type collection variable in Salesforce?
Posted by kapil on January 12, 2018 at 6:37 AMWhy we cannot perform DML operation on SET type collection variable in Salesforce?
shariq replied 7 years, 7 months ago 4 Members · 3 Replies -
3 Replies
-
Hello Kapil,
Yes, we can’t perform DML operation on Set collection –
1) List -> Ordered(Allows indexing), Allow duplicacy and Allow DML.
List<Integer> lstArr = new List<Integer>{1, 2, 3};
system.debug(lstArr[1]); //Valid1) Set-> Unordered(Does not allows indexing) and did’t Allow duplicacy.
Set<Integer> setArr= new Set<Integer>{1, 2, 3};
system.debug(setArr[1]); //Not validFor DML operation – In the case of sets ,we can’t use DML over sObjects. in that we need to add all Data in set to list and go for DML once again.
Hope it helps 🙂
- [adinserter block='9']
-
Yes, we cannot perform DML operation on collection variables. But for DML operation you need to add all Data in set and then go for DML.
Thanks
-
Hi,
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
Hope this helps.
Log In to reply.