Loading

How to Create a Parent-Child Hierarchy in the Same Salesforce Custom Object Using Lookup Relationships

Publiceringsdatum: May 13, 2026
Beskrivning

In Salesforce, standard objects like Accounts support a built-in hierarchy feature (for example, Account Hierarchy). However, for custom objects, Salesforce does not natively provide a self-referential parent-child hierarchy.
This article explains how to simulate a parent-child hierarchy within the same Salesforce custom object — for example, a hierarchy of Opportunities — by creating a separate intermediate custom object that uses two Lookup Relationship fields pointing back to the parent object. This approach works for any custom object where a hierarchical relationship is needed.
Note: This is not a built-in Salesforce CRM feature for standard custom objects. The workaround requires creating an intermediate custom object.

Lösning

The following steps create a parent-child hierarchy for a custom object by using an intermediary custom object with two lookup fields — one pointing to the Parent record and one to the Child (Sub) record.

Step 1: Create the Intermediary Custom Object

Navigate to Custom Objects in Setup:

  • In Salesforce Classic: Setup > App Setup > Create > Objects > New Custom Object
  • In Salesforce Lightning: Gear Icon > Setup > Object Manager > Create > Custom Objects
  1. Name the object Sub (for example, SubOpportunity).
  2. Select Auto Number for the Data Type.
  3. Do not select any of the Optional Features or Object Creation options.
  4. Click Save.

Step 2: Create the Parent Lookup Relationship

Create the first Custom Relationship within the new object to establish the Parent:

  1. Data Type = Lookup Relationship
  2. Related To = Select the object you want to create the hierarchy in
  3. Field Label = Parent (for example, ParentOpportunity)
  4. Related List Label = Sub
  5. Click Save.

Step 3: Create the Sub (Child) Lookup Relationship

Create the second Custom Relationship within the new object to select the Sub (child):

  1. Data Type = Lookup Relationship
  2. Related To = Select the same object as above
  3. Field Label = Sub (for example, SubOpportunity)
  4. Related List Label = Parent
  5. Click Save.

Step 4: Update Page Layouts

Navigate to Page Layouts in Setup:

  • In Salesforce Classic: Setup > App Setup > Customize > [Object] > Page Layouts > Edit > Related List Section > Select the Sub object
  • In Salesforce Lightning: Gear Icon > Setup > Object Manager > Select the Sub custom object > Page Layouts > Edit > Related List Section
  1. Edit Related List Properties for the Sub related list.
  2. Move the Sub field from Available Fields to Selected Fields. Click OK.
  3. Save the Page Layout.
  4. Edit Related List Properties for the Parent related list.
  5. Move the Parent field from Available Fields to Selected Fields. Click OK.
  6. Save the Page Layout.

Users can now create a new Sub record that references another record in a parent-child hierarchical setup.

For additional information related to object relationships please review the article below:

https://help.salesforce.com/articleView?id=overview_of_custom_object_relationships.htm&type=5

See Also: Set Up Account Hierarchy in Lightning Experience

Knowledge-artikelnummer

000385441

 
Laddar
Salesforce Help | Article