For the complete documentation index, see llms.txt. This page is also available as Markdown.

Quickly Traverse Five Levels

Salesforce allows SOQL queries and merge fields to traverse up to five relationship levels. Understanding these levels helps leverage existing objects efficiently. Here’s a guide to navigating five levels:

  • Starting Point: Identify the base object (e.g., Task, Opportunity, Case).

  • Relationship Levels: Each step represents a related object or field traversed.

Examples

Example 1: Opportunity to User (via Account)

Merge Field:

{!Opportunity.Account.Parent.Owner.Profile.Name}

Levels Breakdown:

  1. Opportunity

  2. Account (related to Opportunity)

  3. Parent (parent Account of Account)

  4. Owner (User who owns the parent Account)

  5. Profile.Name (Profile name of the User)

Example 2: Account to Work Order Line Items

This example SOQL relationship query returns records from the parent object Account and its child objects Contacts, Assets, WorkOrders, and WorkOrderLineItems.

SELECT Name,
    (SELECT LastName,
        (SELECT AssetLevel,
            (SELECT Description,
                (SELECT LineItemNumber FROM WorkOrderLineItems)
            FROM WorkOrders)
        FROM Assets)
    FROM Contacts)
FROM Account

Last updated

Was this helpful?