function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Brooks Bruce 47Brooks Bruce 47 

SOQL query for Parent and Child sObject fields

Why is it necessary to have a nested for loop to go through results when a query from a parent sObject includes fields from the child sObject, but not when the query is from the child sObject and includes parent fields? 

Thank you.
Best Answer chosen by Brooks Bruce 47
Kevin CrossKevin Cross
Because in a parent-child relationship, there usually are multiple children per parent.  Therefore, you need a loop to make sure you look at each child record.

All Answers

Kevin CrossKevin Cross
Because in a parent-child relationship, there usually are multiple children per parent.  Therefore, you need a loop to make sure you look at each child record.
This was selected as the best answer
Brooks Bruce 47Brooks Bruce 47
(facepalm). Thanks, Kevin!