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
chim chim 9chim chim 9 

Hi. I made a parent-child query, the thing is i want to call the child data from my query but i dont know the proper code to put

This is my query:
Account[] oldAcc = [Select Id, BillingStreet, (Select Id, AccountId, MailingStreet from Contacts)Name from Account Limit 10]

I tried using oldAcc.Contact but i got no values when i tried it using system debug.
Best Answer chosen by chim chim 9
AbhinavAbhinav (Salesforce Developers) 
Hi Chim,

Exexute query from query editor as well to check whether Account has related contact or not

Select Id, BillingStreet, Name,(Select Id, AccountId, MailingStreet from Contacts) from Account Limit 10
 
List<Account> oldAcc = [Select Id, BillingStreet, Name,(Select Id, AccountId, MailingStreet from Contacts) from Account Limit 10]

for(Account a:oldAcc)
{
for(Contact c: a.contacts)
{
System.debug("---->Contact--->"+c)
}
}

If it helps ,Please mark it as best answer.

Thanks!

 

All Answers

chim chim 9chim chim 9
To get you an idea of what i'm trying to do:
I want to modify the Billing street from the queried Accounts and at the same time change the mailing street of the related contacts of each account
AbhinavAbhinav (Salesforce Developers) 
Hi Chim,

Exexute query from query editor as well to check whether Account has related contact or not

Select Id, BillingStreet, Name,(Select Id, AccountId, MailingStreet from Contacts) from Account Limit 10
 
List<Account> oldAcc = [Select Id, BillingStreet, Name,(Select Id, AccountId, MailingStreet from Contacts) from Account Limit 10]

for(Account a:oldAcc)
{
for(Contact c: a.contacts)
{
System.debug("---->Contact--->"+c)
}
}

If it helps ,Please mark it as best answer.

Thanks!

 
This was selected as the best answer