error

Foreign key relationship not supported

What does this error mean?

This error occurs when a SOQL query attempts to traverse a relationship that Salesforce does not support.

SOQL supports parent-to-child and child-to-parent relationships, but only when those relationships are defined and supported by the object schema.

Common Causes

1. Incorrect relationship name

Using an incorrect relationship name in a SOQL query.

2. Querying unsupported relationships

Some objects do not support direct relationship traversal.

3. Using wrong child relationship name

The child relationship name defined in the lookup or master-detail field may be different.

4. Querying polymorphic relationships incorrectly

Objects like Task or Event may reference multiple object types.

How to Fix It

Solution 1 — Check relationship name

SOQL

SELECT Id, Account.Name
FROM Contact

Solution 2 — Use correct child relationship name

SOQL

SELECT Id,
       (SELECT Id, Name FROM Contacts)
FROM Account

Solution 3 — Query objects separately

Apex

Map accountMap = new Map(
    [SELECT Id, Name FROM Account]
);

Solution 4 — Check Object Manager

Verify relationship names in:


Setup → Object Manager → Fields & Relationships
lightbulb

Pro Tip: Use the Schema Builder or describe metadata to identify correct relationship names before writing SOQL queries.