How do you write a Child-to-Parent query on Standard Objects vs Custom Objects (__r)?
Answer
Use dot notation on the relationship name.
- Standard lookup: relationship name is the field name without Id, e.g.
AccountforAccountId. - Custom lookup/master-detail: field
Department__cbecomesDepartment__r.
soql
SELECT Name, Account.Name, Account.Industry FROM Contact
SELECT Name, Department__r.Name, Department__r.Manager__r.Name FROM Employee__c
Standard: Account.Name; custom: Parent__r.Name.
soqlrelationshipschild-to-parent