Set Child Relationship Name on custom Relationship fields

This post only applies to relationship fields (lookup and master-detail) that went through the Winter ’07 upgrade.

If you plan to use SOQL relationships in queries that have custom relationships to other objects, you should go and edit your custom relationship fields to include a Child Relationship Name. This allows you to use a user-friendly name for the relationship when querying the master object.

Going forward, this field is set for you. However, after the Winter 07 upgrade, this field was left blank on all relationship fields. Without making this update, SOQL relationships will still work, but you will be forced to use an archaic value for the relationship name. That archaic value will look like a Salesforce ID.

The Salesforce online help has very good documentation on relationships, but here’s a quick example.

Suppose you had 2 custom objects before the Winter 07 upgrade: Quote and Quote Line. Quote Line has a relationship field called Quote, which sets a master-detail relationship between quote (master) and quote line (detail). After the Winter 07 upgrade, the Child Relationship Name on that relationship is null. You need to update it. To do so:

  1. Go to your custom object (Quote Line in this example)
  2. Edit the Quote relationship field
  3. Provide a value in the Child Relationship Name field


Doing this allows you to make a query like:

Select q.Name, (Select Id, Name From Quote_Lines__r) From Quote__c q

To get this setup correctly in your org, you should go through each object and make sure this is set for all custom lookup and master-detail relationship fields. You’ll probably use SOQL relationships someday. May as well fix it now.

Comments are closed.