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
skyfjskyfj 

How to get data from Parent table and child table?

Hello,everyone:

       Now, I want to get some datas fromtwo tables(parent and child table).the question is blow:

      [

          Relationship:Parent to child

             .......

             SOQL is this:select a.Id,a.Name,a.Industry,(Select c.Id,c.FirstName,c.LastName From a.Contacts c)

                       From Account a;

             and I can get some datas(a.Id,a.Name,a.Industry) of  "Account" table, and I use blew codes to access the   "Contact" object,but qr always is null,why? How can I do?

 

              [

                         for (int i = 0; i < qr.records.Length; i++)
                        {
                              account = (Account)qr.records[i];
                             QueryResult qr = account.Contacts;

                              .......
                         } 

              ]

 

             Relationship:Child to Parent

             .......

             SOQL is this:Select Id, FirstName,MailingCity from Contact where Account.Name like '%a%'

             .......

              for (int i = 0; i < qr.records.Length; i++)
              {
                    contact = (Contact)qr.records[i];
                    Account acc = (Account)contact.Account;
                    here, acc alwasy is null,I don't know how to do?

              }

 

      ]

 

      Who can give me some advises  or a completely example of getting datas from two tables(Parent and childe)?

 

sincerely

 

skyfj