Skip to main content

i am new to salesfoce and have query like this

list<account> accList= [select id, name,  accountNumber (select id, firtName, LastName, phone from contacts) from account];

now i want to display records of account name in one system.debug  and display firstName and phone values in another system.debug i am confusing nested for loop could any help me on this
3 answers
  1. Aug 31, 2020, 6:46 AM
    Hi Prashanth,

    You can use the below code snippet:

    for(Account acc : accList) {

    system.debug(acc.Name);

    for(Contact con : acc.Contacts) {

    system.debug(con.FirstName);

    system.debug(con.Phone);

    }

    }

    Let me know if you need any further help.

    Thanks,

    Abhishek Bansal.
0/9000