From 459dc66d5c7ec22154e52e3ef522d9d6db85f86f Mon Sep 17 00:00:00 2001 From: Ilija Pavlic Date: Thu, 28 Sep 2023 11:45:52 -0400 Subject: [PATCH] Restore ObjectCollection --- .../classes/collection/ObjectCollection.cls | 27 +++++++++++++++++++ .../collection/ObjectCollection.cls-meta.xml | 5 ++++ .../classes/collection/SObjectCollection.cls | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 force-app/main/default/classes/collection/ObjectCollection.cls create mode 100644 force-app/main/default/classes/collection/ObjectCollection.cls-meta.xml diff --git a/force-app/main/default/classes/collection/ObjectCollection.cls b/force-app/main/default/classes/collection/ObjectCollection.cls new file mode 100644 index 0000000..9a86b1e --- /dev/null +++ b/force-app/main/default/classes/collection/ObjectCollection.cls @@ -0,0 +1,27 @@ +public with sharing class ObjectCollection { + private List objects; + + public static ObjectCollection of(Iterable objects) { + return new ObjectCOllection(objects); + } + + private ObjectCollection(Iterable objects) { + this.objects = new List(); + Iterator iter = objects.iterator(); + while (iter.hasNext()) { + this.objects.add(iter.next()); + } + } + + public List asList(Type listType) { + List typedObjects = (List) listType.newInstance(); + typedObjects.addAll(objects); + return typedObjects; + } + + public Set asSet(Type setType) { + Set typedObjects = (Set) setType.newInstance(); + typedObjects.addAll(objects); + return typedObjects; + } +} diff --git a/force-app/main/default/classes/collection/ObjectCollection.cls-meta.xml b/force-app/main/default/classes/collection/ObjectCollection.cls-meta.xml new file mode 100644 index 0000000..642d054 --- /dev/null +++ b/force-app/main/default/classes/collection/ObjectCollection.cls-meta.xml @@ -0,0 +1,5 @@ + + + 58.0 + Active + \ No newline at end of file diff --git a/force-app/main/default/classes/collection/SObjectCollection.cls b/force-app/main/default/classes/collection/SObjectCollection.cls index 07a012c..5cd71ea 100644 --- a/force-app/main/default/classes/collection/SObjectCollection.cls +++ b/force-app/main/default/classes/collection/SObjectCollection.cls @@ -388,7 +388,7 @@ public with sharing class SObjectCollection { for (SObject record : records) { mapped.add(fn.call(record)); } - return new ObjectCollection(mapped); + return ObjectCollection.of(mapped); } public SObjectCollection mapSome(SObjectPredicate predicate, SObjectToSObjectFunction fn) {