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
eriklangeriklang 

SOQL question - are subqueries possible?

Here's what I want to do: get a list of Accounts with SOQL, and for each account, I want the name of the Account Team Member whose role is "Implementation Consultant"  For example: Client Name = Jane's Car Wash, Implementation Consultant = Jane Doe ... Client Name = Bob's Burgers, Implementation Consultant = Bob Smith ... etc.  Just like a SQL subquery.

Why I want to do this: my client wants to display the implementation consultant's name in a grid where there's one client per row.  I think it would affect performance too much to do one team member search per row - there will be lots of rows, all visible on the same page, and every search seems to take at least a second or two.

Is it possible?  If not, is there a recommended way to do what I'm trying to do?
BalajiRanganathanBalajiRanganathan

you can try below SOQL. 

SELECT AAC_Contact__c, (SELECT UserId,user.firstname, user.lastname,TeamMemberRole FROM AccountTeamMembers where TeamMemberRole ='Implementation Consultant') FROM Account where id in : list

refer this link for relationship queries in soql.

http://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_relationships.htm