Trying to work with a Master-Detail relationship in apex. The following code will produce a Case with several child records, and I can use list methods to access the records (i.e. the system.debug statement produces a child record). I would like to do something like this
List<Child_Records__c> newList = c.Child_Records__r;
And add all the child records to a newList to work with the data.
However, this syntax results in the list having a
size() = 0.
Case c = [ SELECT Id, ( SELECT Id, Maintenance_Request__c, Equipment__r.Name, Equipment__r.Maintenance_Cycle__c FROM Equipment_Maintenance_Items__r ORDER BY Equipment__r.Maintenance_Cycle__c ASC ) FROM Case LIMIT 1 ]; System.debug(c.Equipment_Maintenance_Items__r.get(0));
Is there a short shorthand way of creating a list of child records from the parent?