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
gvgv 

SOQL Question

 

I have a SOQL query like the following
Select a.id,a.name,a.lastmodifiedby,(select id from related_accounts__r where main_account__c = '') from account where a.id = ''
Basically teh related_accounts__r is a child relationship for the account object.
I am not sure how would I access the inner id in my code?
I think I have done this in the past but don't remember how?
Thanks


I have a SOQL query like the following
Select a.id,a.name,a.lastmodifiedby,(select id from related_accounts__r where main_account__c = '') from account where a.id = ''
Basically teh related_accounts__r is a child relationship for the account object.
I am not sure how would I access the inner id in my code?
I think I have done this in the past but don't remember how?
Thanks

 

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

the outer account records will have a related_accounts__r property that's an array of the inner rows for that outer row, so you'd do something like

 

for (Account  a: [select ....]) {

for (related_account__c r : a.related_accounts__r) {

System.debug (r.id + " is a child of " + a.id);

}

}