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?

marked as duplicate by sfdcfox soql Oct 10 '18 at 16:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • I've linked four other questions that demonstrate a number of ways to find the relationship, including Apex Code, workbench, etc, as well. – sfdcfox Oct 10 '18 at 16:02
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 or ask your own question.