I have an ordered list of a custom object which is the child of a different object. I want to get the earliest date of the child object per parent object. Here is a basic example:
List<objB__c> relChild = [SELECT id, objA__c, date
FROM objB__c
WHERE objA__c IN: objASet
ORDER BY date NULLS LAST];
So I should have a list of all children (objB) for any parent (objA) that I already have in a Set I had created earlier. Almost all the time there will only be one record in objASet, but I am trying to "bulkify" my code and allow it to handle multiple records just in case.
How can I pull the earliest date field from my list for each objA? Can I create a Map of id,Date and just iterate through the list? Or do I have to create a wrapper? Or can I use the sort method in some way?
Here is my idea for just doing a simple iteration:
Map<id,date> firstDate = new Map<id,date>();
for(objB__c b: relChild){
if(firstDate.containsKey(b.objA__c){} else {
firstDate.put(b.objA__c, date); //would this get me the first date for each objA__c?
}
}
if
block...