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
LJanikLJanik 

Populating List of Custom Child Objects from Query

I am trying to populate a list of custom child objects through a query.  The following code does not work

List<child__c> childlist; childlist=database.query('SELECT child__r.last_name__c, child__r.first_name__c FROM parent__c');

 

srisomsrisom

Something like this:

 

List<Parent__c> parentList = [Select Id, (Select Name From Children__r) From Parent__c];

List<Child__c> children_for_parent = parentList.get(0).Children__r;  // children for first parent

 

Here the plural name for child in my setup is children - hence the children__r relationship name.  You would probably put in a loop here.

 

Hope this is what you are after.