function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jerry22jerry22 

how to find the right child relationship name?

hi everbody,

i know there are a lot of posts on child relationship name, but I still wasn't able to solve my problem:
I want to update my test-page to removing a unwanted related list from "Opportunitys". I want to remove "Contact Roles".

I tryed the following code:

<apex:page standardController="Opportunity">
<b>Hello {!$User.FirstName}!</b> <br/><br/>
<apex:detail relatedList="false" />
<apex:relatedList list="ContactRole" />   
</apex:page>

 

But I get this error:

'ContactRole' is not a valid child relationship name for entity Opportunity
Any Idea??

 

Best Answer chosen by Admin (Salesforce Developers) 
colemabcolemab

Jerry,

 

I can't explain to you what "task nr.5 supposed to mean" without seeing your assessment instructions directly.

 

I can tell you that this code will display the apex page w/ only the related list in quesiton:

 

<apex:page standardController="Opportunity">
<b>Hello {!$User.FirstName}!</b> <br/><br/>
<apex:detail relatedList="false" />
<apex:relatedList list="OpportunityContactRoles" />  
</apex:page>

 

Also, as long as relatedlist="false" in your <apex:detail> tag, you *cannot* display the hover links for the related list (i.e. what you call the whole related list link). 

 

The releadListHover boolean controls this but it gets ignored whenever relatedlist="false" and you want it to be set to false to only display the releated lists you want (as opposed to the default layout).

 

Here is the documentation around that setting:

 

relatedListHoverBoolean

A Boolean value that specifies whether the related list hover links are included in the rendered component. If true, the related list hover links are displayed. If not specified, this value defaults to true. Note that this attribute is ignored if the relatedList attribute is false, or if the "Enable Related List Hover Links" option is not selected under Setup | Customize | User Interface.

All Answers

colemabcolemab

I am confused by you saying you want to remove a list but then you show code to add a list.  So I am going to try and touch all the bases here.

 

If you are editing a standard page layout, you can simply remove the related list from the layout.

 

If you want to remove an unwanted related list for contact roles, you will need to remove this line:

<apex:relatedList list="ContactRole" />  

 

HOWEVER, if you you want to *add* the related list you are on the right path but your list is set wrong.   I think you real question is, how do I find the relationship name for this list?

 

The *best* (not easisest) way to do this is to look in your WSDL.  Goto Setup->Develop->API->Generate Enterprise WSDL

 

Save this XML file to disk and open in your text editor.  Search for "<complexType name="Opportunity">"

 

In that section, any element name that has type="tns:QueryResult"  is a relationship and the name will be the relationship name.  Here is an example:

 

<element name="OpportunityContactRoles" nillable="true" minOccurs="0" type="tns:QueryResult"/>

 

So for your case, I think you are looking for this:

<apex:relatedList list="OpportunityContactRoles" />   

 

jerry22jerry22

Maybe I got the task wrong. In order to avoid missunderstandings:
For a assessment I got asked to create a page via visualforce acording to a existing exercise-sheet. They also told me my developer edition hasn’t got the “Object” (“Position”) which is used in the exercise sheet . So they told me to use “Opportunitys” instead of “Position”. The task in the original sheet says this:

 

5. Update the page to remove unwanted related list :

a) change the code as follows to use only specific related lists:

 <apex:page standardController="Position__c">
<b>Hello {!$User.FirstName}!</b> <br/><br/>
<apex:detail relatedList="false" />
<apex:relatedList list="Job_Applications__r" />  
</apex:page>

 

So I did this: :

 

apex:page standardController="Opportunity">
<b>Hello {!$User.FirstName}!</b> <br/><br/>
<apex:detail relatedList="false" />
<apex:relatedList list="ContactRoles" />  
</apex:page>

 

When I follow your suggestion and use “OpportunityContactRoles” I don’t get an Error at least, but the “whole” related link list dissapears ( with whole I mean: Products[0] | Open Activities[0] | Activity History[1] | Notes &amp; Attachments[0] | Contact Roles[1] | Partners[0] | Competitors[0] | Stage History[2]). I thought that “only” Contact Roles should either stay or dissapear.
So probably my 1st question should be:
What is task nr.5 supposed to mean?: “Job Application” (alternatively “Contact Role”) is supposed to be *visible* or *not visible*?


 
colemabcolemab

Jerry,

 

I can't explain to you what "task nr.5 supposed to mean" without seeing your assessment instructions directly.

 

I can tell you that this code will display the apex page w/ only the related list in quesiton:

 

<apex:page standardController="Opportunity">
<b>Hello {!$User.FirstName}!</b> <br/><br/>
<apex:detail relatedList="false" />
<apex:relatedList list="OpportunityContactRoles" />  
</apex:page>

 

Also, as long as relatedlist="false" in your <apex:detail> tag, you *cannot* display the hover links for the related list (i.e. what you call the whole related list link). 

 

The releadListHover boolean controls this but it gets ignored whenever relatedlist="false" and you want it to be set to false to only display the releated lists you want (as opposed to the default layout).

 

Here is the documentation around that setting:

 

relatedListHoverBoolean

A Boolean value that specifies whether the related list hover links are included in the rendered component. If true, the related list hover links are displayed. If not specified, this value defaults to true. Note that this attribute is ignored if the relatedList attribute is false, or if the "Enable Related List Hover Links" option is not selected under Setup | Customize | User Interface.

This was selected as the best answer