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
rajjjjrajjjj 

parent child relationship queries

HI All,

 I have a doubt here.In the following query

SELECT Name,
  (
    SELECT CreatedBy.Name
    FROM Notes
  )
FROM Account

 Account is the parent object and notes is the child object.

In the nested query it is using CreatedBy.Name.....so that means Notes is parent and User is child.....Is that correct???

If that is true....i dont see any field called CreatedBy in notes....i am able to see only CreatedById.

Please clarify me on this.

Kartik PerisetlaKartik Perisetla

Hi Raj,

 

Each object in Force.com has got Lookup to User object. Hence once you create a record under  a object it will store recordID of user who created it in the CreatedBy field. For every object on Force.com you can see CreatedBy field. Since CreatedBy field points to User record you need to explicitly use fields like "Name","Alias",etc to get their field values.

 

I hope you find this response useful.

 

Cheers !

 

 

rajjjjrajjjj

So the User is Parent here and Notes is Child......But it looks opposite for me????

Starz26Starz26

No...

 

The createdby uses a hierarchical lookup on the user object (lookup to itself). One of those special cases. (IIRC)

Kartik PerisetlaKartik Perisetla

Hi Raj,

 

No the Notes object is not the parent object. Every object has got lookup to User object the information like who created the record in that object and his further details are then retrieved using it.

 

I hope you find this response useful.

 

Cheers !