Home / Blog / SFDC Best Practice for Child Relationship Names

SFDC Best Practice for Child Relationship Names

Please declare a unique Child Relationship Name! Think of it as just as important as the Related List Label (which is what your Salesforce users see). The Child Relationship Name is what developers see when writing sub queries in Apex. Salesforce uniquely names Child Relationships if you don’t. However, those names are generally useless for developers trying to fully understand the relationship if there’s more than one Child Relationship from the given object.

I’ve encountered this issue on several clients’ orgs.  Recently, one I worked on had multiple Lookup fields on the Account object relating back to the Account object. While this is okay to do, make sure to name the Child Relationships appropriately. Here’s an example of what they had for one of their Lookups:

Child Relationship in SFDC
Child Relationship in SFDC

Looking further into the schema on the Account object, we see three other child relationships from Account (and coincidently “to Account” in this example):

Child Relationship in SFDC
Child Relationship in SFDC

A simple refactor to something like a “indentifierSObject” pattern would be better choice.

So instead of:

  • Accounts__r
  • GeneralConsultant__r
  • Accounts1__r

We end up with something like:

  • AdAgencyAccounts__r
  • GeneralConsultantAccounts__r
  • RE_ConsultantAccounts__r

SFDC will limit the number characters in the Child Relationship Name, so figure out what communicates best.

This will make all future developers of the codebase much happier.

Happy clouds ~~~

Leave a Comment

Your email address will not be published. Required fields are marked *