You need to sign in to do that
Don't have an account?
MySet
SOQL
Can't we view the child records in developer console?
List<Account> acc = [SELECT ID,Name,(Select Id, LastName FROM Account.Contacts) FROM Account];
System.debug('See the SOQL' +acc);
-MySet
for(Account acc : [SELECT ID,Name,(Select Id, LastName FROM Contacts) FROM Account])
{
for(Contact con : acc.Contacts)
{
System.debug('@@@@' + con);
}
}
If this post sovles your problem please mark it as solution.
Hope this helps.
Thanks,
Samba
Debug will not untill you specify what you are looking for...go for this one..
List<Account> acc = [SELECT ID,Name,(Select Id, LastName FROM Contacts) FROM Account];
system.debug('##### value of your account's contact' + acc[0].contacts);
This works fine
Regards
Abhi
Hi Samba,
Thank you for your answer. Can you guide me to run the code in developer console? I have written the below by taking the help of your snippet.
It's not working. Can you point out my mistake?
public class MyClass{
List<Contact> conlst = new List<>(Contact);
public showContacts(){
for(Account acc:[SELECt id,Name,(Select Id, LastName From Contacts) From Account]){
for(Contact con:acc.contacts){
conlst.add(con);
System.debug('List of all Contacts' + conlst);
}
}
}
}
1. please update "List<Contact> conlst = new List<>(Contact);" to List<Contact> conlst = new List<Contact>();
2. public showContacts(): this method is not a construction method. you need to add a result type.
Hope this helps.
Thanks,
Samba
Developer Console -> Debug -> Open Execute Anonymous Window
Go and paste your code there and check your debug values after clicking execute.
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Looks great.
Hi,
I ran the below code but getting the error:
public class Myclass{
List<Contact> conlst = new List<Contact>();
for(Account acc:[SELECT id,Name,(Select Id, LastName From Contacts) From Account]){
for(Contact con:acc.contacts){
conlst .add(con);
System.debug('List of all Contacts' + conlst);
return conlst;
}
}
}
if you want to run you code in Developer Console, please remove your class name. you can run:
List<Contact> conlst = new List<Contact>();
for(Account acc:[SELECT id,Name,(Select Id, LastName From Contacts) From Account]){
for(Contact con:acc.contacts){
conlst .add(con);
System.debug('List of all Contacts' + conlst);
return conlst;
}
}
Thanks,
Samba
Thank you guys. Going a little deeper. I have 29 records, but in system log it is showing only 1 record.
16:10:54:052 USER_DEBUG [8]|DEBUG|List of all Contacts(Contact:{AccountId=0019000000KGTofAAH, Id=0039000000J1PlHAAV, LastName=Frank})