Definition
A Child Relationship in Salesforce describes the connection from a child object to a parent object in a master-detail or lookup relationship. The child object contains the relationship field that points to the parent. Child relationships are referenced in SOQL subqueries using the relationship name (e.g., querying Contacts as a child relationship of Account). The relationship name is used for building queries, related lists, and cross-object formulas.
Real-World Example
When a developer at Quantum Labs needs to streamline operations, they turn to Child Relationship to build a custom solution that extends the platform beyond its standard capabilities. They write clean, bulkified code for Child Relationship, add comprehensive test coverage, and deploy it through a CI/CD pipeline. The new functionality handles 10,000 records without hitting governor limits.
Why Child Relationship Matters
A Child Relationship describes the perspective from a child object looking back at its parent in a master-detail or lookup relationship. Every relationship in Salesforce has two sides: the parent looks down at children through the Child Relationship, and the child looks up at the parent through the lookup or master-detail field. The Child Relationship has a name (configured when the relationship is defined) that's used in SOQL subqueries, related lists, and cross-object formulas to navigate from parent to children.
In SOQL, you use the Child Relationship name in a subquery like this: SELECT Id, Name, (SELECT Id, FirstName, LastName FROM Contacts) FROM Account. The 'Contacts' inside the parentheses is the Child Relationship name on Account that points back to all related Contact records. Child Relationship names are typically the plural form of the child object name (Contacts, Opportunities, Cases) for standard objects, and admins choose them for custom objects when defining the relationship field. Picking a clear, plural Child Relationship name is important because it shows up in SOQL queries throughout the codebase.
How Organizations Use Child Relationship
- •Quantum Labs — Uses a Child Relationship name they defined as 'Project_Members__r' on a custom Project__c object to query all related Project Member records in a single SOQL query. The relationship name is consistent across the codebase.
- •TerraForm Tech — Renamed a Child Relationship after discovering the auto-generated name was inconsistent with their naming convention. The rename required updating every SOQL query that used the old name, which was a useful reminder to choose names carefully upfront.
- •CodeBridge — Documented every custom Child Relationship name in their data dictionary so developers know what to use in queries without having to look it up in the field metadata each time.
