+ Start a Discussion

display one child record id on another child record

Hi All,
I have the below requirement. I have one parent and 2 childs. i want to get ids of two child records and update a field with id of child 2 on child1 and vice versa. How can i do this?

You can use inner query for querring child record from parent
for eg:
consider this scenario,
account as parent , contact and opportunity as child
select name,id,(select id,name from contacts),(select id,name from opportunities) from account
list<account> ac=[select name,id,(select id,name from contacts),(select id,name from opportunities) from account];
for(account a:ac)
    for(contact c:a.contacts)
     for(opportunity o:a.opportunities)
Hope this helps..
Ajay K DubediAjay K Dubedi
Hi Chubby,

Nested SOQL : 

In Nested SOQL, we can retrieve the data of the related object using the SOQL query. We can query on the parent object and get details about parent and child records.

For example, following SOQL query retrieves Accounts, related Contacts, and related Cases associated with each Account:

Select Id, Name, (Select Id From Contacts), (Select Id From Cases) from Account LIMIT 10

Please mark as best answer if it helps you.

Thank You, 
Ajay Dubedi
 Thanks for your thoughts.
 Here I have Account and contact1, contact2. I need to query and then update Id in contact1 with Id of contact2. I am getti the records in query but how to assign values? Please help.