I have a custom object and it's history is shown in UI. I am tracking the certain field. However, I have a problem putting the parentId and list of its history records into the map.
Custom object : TestObject__c
History (standard) : TestObject_History
I need to create a Map that contains the Id of the TestObject__c and its list of TestObject_History in this format:
Map<Id, List<TestObject_History>> parentHistories = new Map<Id, List<TestObject_History>>();
I can create a nested for loop like this:
for(TestObject__c ob : arrayList) {
for(TestObject_History his : [SELECT ParentId, NewValue FROM TestObject_History WHERE ParentId =: ob.Id]) {
// statement
}
}
However, I need to avoid writing the soql query inside the loop. Any other ideas? I would appreciate it.