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
Vikram Singh 157Vikram Singh 157 

Hi ! I am not getting contact first name & Last name from account associates with that account in parent to child relationship

List<Account>accts = [SELECT Account.Name,(SELECT Contact.FirstName, Contact.LastName FROM Account.Contacts) FROM Account];
Devanshu soodDevanshu sood
SELECT name,(SELECT FirstName, LastName FROM Contacts) From Account
try this
Shruti SShruti S
This query works fine for me. Here is what I tried - 
List<Account>accts = [SELECT Account.Name,(SELECT Contact.FirstName, Contact.LastName FROM Account.Contacts) FROM Account];

for( Account acc : accts ) {
    for( Contact con : acc.Contacts ) {
    	System.debug( con.LastName );
    }
}
Please feel free to get back to me if you have any more doubts.
Vikram Singh 157Vikram Singh 157
Hi Shruti & Devanshu Thanks for your hellp.
Shruti SShruti S
Happy to help. Feel free to close the case.