+ Start a Discussion
EpicOfChaosEpicOfChaos 

Issue with apex:relatedList on custom objects

I have a custom object "Retail_Customer_Contract__c" that has child objects "Special_Discount__c" If I go into the master detail field for the relationship the "Child Relationship Name" is "Special_Discounts" but I can not get it to work. I get the follow error :

 

 'Special_Discounts' is not a valid child relationship name for entity Retail Customer Contract


 

Here is my visualForce page

 

 

<apex:page standardController="Retail_Customer_Contract__c" extensions="RetailCustomerContractExtController" ><apex:relatedList list="Special_Discounts"/></apex:page>

 

I have tried every name possible for the list="" attribute. I have tried Special_Discount__c, SpecialDiscount, SpecialDiscounts, etc

 

Any thoughts would be greatly appreciated! 

 

Best Answer chosen by Admin (Salesforce Developers) 
EpicOfChaosEpicOfChaos

Okay I found what I was missing. I need __r on the name so it was "Special_Discounts__r"

 

All Answers

EpicOfChaosEpicOfChaos

Okay I found what I was missing. I need __r on the name so it was "Special_Discounts__r"

 

This was selected as the best answer
newbiewvfdevnewbiewvfdev

Hi there,

 

I am having similar issue. I am getting the following error: 'CampaignMembers' is not a valid child relationship name for entity Campaign

Do you know how to fix this by any chance?

EpicOfChaosEpicOfChaos

I can walk you through how I detemined the correct name to use.

 

go to Setup |  Create | Objects | <Your Child Object>

 

 

Under "Custom Fields & Relationships" click on the field that is the Master-Detail

 

On that page there is a "Child Relationship Name" field. For example on mine it says "Default_Discounts"

 

So you take that name and add __r

 

So it becomes "Default_Discounts__r" that is the value you use in the list attribute. Let me know if you still can't get it.

 

Thanks,

Brody 

newbiewvfdevnewbiewvfdev

Hi Brody,

 

This is what I did for my scenario. In my case Campaign is a standard Object.

 

I went to Setup | Customize | Campaigns | Campaign Members | Fields | Campaign(Look up field)

 

It says Child Relationship Name is 'CampaignMembers'

 

I have tried both code below and both of them do not work:

Code 1: <apex:page standardcontroller="Campaign"> <apex:relatedList list="CampaignMembers"/> </apex:page>

 

Code 2:

<apex:page standardcontroller="Campaign"> <apex:relatedList list="CampaignMembers__r"/> </apex:page>

b-liub-liu

Try using <apex:relatedList list="Campaign_Members__r" />

 

I've been trying to find out the names of the different relationships too but this seems to work.

Ian_CIan_C

Thank you, thank you, thank you. I have searched for this issue all over and nowhere has any answer said where to find the Child Relationship Name. You are my hero.

Apollo-AndyApollo-Andy
Thank you. This helped me find the correct name used.
Phil WPhil W
I know this is an old post, but for others who find this article I discovered that the given error message can be caused by not having the right object and field permissions in the user profile.

For example, if the related list you want is the Accounts for object of type Example__c, where the Accounts are related through Accounts__r from Example__c, you will get the error "'Accounts__r' is not a valid child relationship name for entity Example" if the user's profile doesn't have at least read access to both Account and Account's Example field/relationship (assuming the latter is the relationship name in Account).