Development questions
Write a SOQL query to fetch all child Accounts, parent Accounts, and grandparent Accounts up to 4 levels up (Parent.Parent.Parent.Name).
Walk up the hierarchy through the self-lookup ParentId using chained Parent relationships (up to 5 levels allowed in one path).
soql
SELECT Id, Name, Parent.Name, Parent.Parent.Name, Parent.Parent.Parent.Name, Parent.Parent.Parent.Parent.Name
FROM Account
Each row shows the Account and its parent, grandparent and ancestors up to four levels up. Missing levels return null.
soqlscenariohierarchychild-to-parent
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?