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
prashanth g 10prashanth g 10 

system.debug

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

Best Answer chosen by prashanth g 10
Abhishek BansalAbhishek Bansal
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.

All Answers

Abhishek BansalAbhishek Bansal
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.
This was selected as the best answer
prashanth g 10prashanth g 10
thanks bro
Abhishek BansalAbhishek Bansal
Please close the question by choosing a Best answer if you got your solution. This will help others in future