Development questions

How do you write a Child-to-Parent query on Standard Objects vs Custom Objects (__r)?

DevelopmentEasyTCSWiproTech Mahindra

Use dot notation on the relationship name.

  • Standard lookup: relationship name is the field name without Id, e.g. Account for AccountId.
  • Custom lookup/master-detail: field Department__c becomes Department__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