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
MySetMySet 

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

sambasamba

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

Abhi_TripathiAbhi_Tripathi

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

MySetMySet

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);

        }

     }

    } 
  }

sambasamba

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

souvik9086souvik9086

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

sambasamba

Looks great.

MySetMySet

Hi,

I ran the below code but getting the error: 

 

 
line 4, column 0: expecting right curly bracket, found 'for'
   

 

 

 

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;

            }

       }
 

  }

sambasamba

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

 

MySetMySet

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})