I want to write this simple soql query where in Account there is a ParentId and with it would want to bring the name of this parent (Hierarchy field)
Something like:
select Id, Name, (select Name from Account__r where Id = Account.ParentId)
From Account where id = [xxxxxxx]
I know my Where statement is wrong, just wanted to clarify what it is I want
I have seen many examples of join but never where it is the same table.
Best Answer
You do not need any additional filters to make sure the children are related to the parent. If you write the below query, each row will have an attribute named
ChildAccounts
which contains eachAccount
record whoseParentId
matches the row's ownId
value.If you want to select the parent record instead of children, you would instead do: