I have three custom objects: Entity, Residency, and Address. Entity and Address have a many-to-many relationship; Residency is the junction object (two master-detail relationships.).

Is it possible to access fields on a related Address object from an Entity object? For example, to implement a formula field on Entity which automatically finds the Current Address based on Address move-in date. Or to show one or more objects from the Residency related list (which contains columns from Address objects) in a Visualforce page with standardController="Entity"?

I've used Apex to look at the fields on Entity objects, and Residency__r is not one of them. What are some work-arounds to access data in both directions in a double master-detail relationship? Should I instead create a many-to-many relationship using lookups?



No. You'd have use Visualforce or triggers to determine the current address, depending on your specific needs, such as reporting or display on a record. Formulas can only access parent records, not children records.


The relationship name can differ from the object name. If you go into Setup->Create->Objects->Residency scroll down to the "Custom Fields & Relationships" click on your Master-Detail(Residency) field name and on the right hand side you will see the child relationship name, you will still need to append __r.
Another way of finding out how to refer to a child relationship is through the salesforce.schema in Eclipse. Locate the parent object (Entity) click on the dropdown arrow then click on the dropdown arrow to the left of child relationships, click on the drop down next to the child relationship fields and check one of the fields. You will see the name in the Query Results section.
This works for Visualforce and SOQL queries but as sfdcfox points out would not work for a formula.

  • Right, but the master-detail relationship field is on the Residency object, not the Entity object, so it doesn't appear. Or am I not looking hard enough? – ZakirG Aug 14 '14 at 18:10
  • I think I misunderstood the structure/question. I'll edit my answer appropriately. – Jenny B Aug 14 '14 at 18:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.