• Monali Nanda
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I wanted to add Related Contact records from Account Object in a Contact array. But I'm getting  error in doing so.
 
Account[] acctsWithContacts = [SELECT Name, (SELECT FirstName,LastName FROM Contacts)FROM Account limit 10];   
                              
// Get child records 
 
Contact[] cts = acctsWithContacts.Contacts;    //(Here I'm getting the error)
 
System.debug('Name of first associated contact: ' + cts[0].FirstName + ', ' + cts[0].LastName);