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
NakataNakata 

How to retrieve subquery result from SOQL ?

Good day, 

 

If i have following query :

 

 

Select a.Name , (Select userId From AccountTeamMembers WHERE TeamMemberRole='Sales') From Account a where id='0013000000H0EMSS'

 

 

How can i get the userId ?

 

Thanks in advance !

Best Answer chosen by Admin (Salesforce Developers) 
Shailesh DeshpandeShailesh Deshpande

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

 

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

for (AccountTeamMember at : a.AcountTeamMembers) {

System.debug (at.userId);

}

}

All Answers

Shailesh DeshpandeShailesh Deshpande

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

 

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

for (AccountTeamMember at : a.AcountTeamMembers) {

System.debug (at.userId);

}

}

This was selected as the best answer
NakataNakata

Thanks 

ramifyramify
Thank you shailesh
smriti sharan19smriti sharan19
for ( Account acc : [ SELECT Id, name,(SELECT id FROM AcountTeamMembers) FROM Account ] ) {
     for ( AcountTeamMember at: acc.AcountTeamMembers) {
      }