0

In Trailhead we have the query to get the Contacts for the Account named "SFDC Computing", with an inner query.

 SELECT Name, (SELECT LastName FROM Contacts) FROM Account WHERE Name = 'SFDC Computing'

It works fine for my purposes. "Contacts" is the name of the relationship, per Trailhead. So, I went to Object Manager and examined the Account object's "Fields and Relationships". There is nothing named "Contacts"!

In general, how do I get the name of the relationship, for use in similar SOQL queries?

1
  • I've linked four other questions that demonstrate a number of ways to find the relationship, including Apex Code, workbench, etc, as well.
    – sfdcfox
    Commented Oct 10, 2018 at 16:02

1 Answer 1

2

You look at the relationship lookup field on the child object. Here's an example from Contact, whose lookup field to Account is AccountId:

enter image description here

For custom relationship fields, the relationship name must be postfixed with __r in SOQL, and queries against objects in a different namespace must be prefixed with the relevant namespace, i.e., MyNs__My_Relationship__r.

Not the answer you're looking for? Browse other questions tagged .