Is there a way to get related records using something like {!Account.Contacts}
in a VF page with Custom Objects? Does the type of relationship matter? If I have a custom object and it has a look up relationship with another custom object, will something like {!Custom_Object1__c.Custom_Object2__c}
work? Do I have to write an extension to query the appropriate records?
With standard controllers, you can access one level of child relationships. See Accessing Data with a Standard Controller:
You can traverse one level of parent-to-child relationships. For example, if using the Account standard controller, you can use {!account.Contacts} to return an array of all contacts associated with the account that is currently in context.
As for custom objects with a look-up relationship, you will be able to access them as well, but you need to use the child relationship name:
{!Custom_Object1__c.Custom_Object2s__r}
Note the __r suffix, and the child relationship name is the pluralized form of the object name since that is how it was defined when creating the look-up field (if you are unsure of the relationship name between your two objects, check the lookup field definition).
-
Thank you! There were two issues in the code I had:One, I only had a single underscore for the relationship. Two, I noticed that on the relationship field itself there is a definition for the 'Child Relationship Name'. In this case, it was not pluralized. Once I removed the 's', it worked. This is great because now I can use the standard set controller functionality. – VanAlfredo Mar 24 '17 at 3:44
-