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
Carole Reynolds1Carole Reynolds1 

VP Page standardController Opportunity - Get Contact Name from Contact Roles

I have a VF page that uses the standardController for Opportunity. Is there a way, without writing an extension class, to get the Contact Name from the Contact Roles related list?

I found a solution for my email template that works like a charm (see below), but I'm struggling getting it to work on the VF page that is used by a custom button. I'm a developerless novice admin, pardon my ignorance. 

 

Working in VF Email Template: 

<apex:repeat value="{!RelatedTo.OpportunityContactRoles}" var="ContactRole"> {!ContactRole.Contact.Name}</apex:repeat>

Best Answer chosen by Carole Reynolds1
Terence_ChiuTerence_Chiu
Here are two examples of dispaying opportunity contact role information onto a VF page. 

Example 1 uses the related list component to render the contact roles related list onto the page. It will look like the related list displayed on the standard opportunity page layout.

Example 2 uses the pageblocktable component to iterate through the list of contact role records. The column component is used to render individual field data onto the table.
 
<apex:page standardController="Opportunity">

    <!--EXAMPLE ONE-->
    <apex:relatedList list="OpportunityContactRoles"/>
    
    <!--EXAMPLE TWO-->
    <apex:pageBlock >
        <apex:pageblockTable value="{!Opportunity.OpportunityContactRoles}" var="cr">
            <apex:column value="{!cr.Contact.Name}"/>
            <apex:column value="{!cr.Role}"/>
        </apex:pageblockTable>
    </apex:pageBlock>
</apex:page>
User-added image
 

All Answers

Terence_ChiuTerence_Chiu
Here are two examples of dispaying opportunity contact role information onto a VF page. 

Example 1 uses the related list component to render the contact roles related list onto the page. It will look like the related list displayed on the standard opportunity page layout.

Example 2 uses the pageblocktable component to iterate through the list of contact role records. The column component is used to render individual field data onto the table.
 
<apex:page standardController="Opportunity">

    <!--EXAMPLE ONE-->
    <apex:relatedList list="OpportunityContactRoles"/>
    
    <!--EXAMPLE TWO-->
    <apex:pageBlock >
        <apex:pageblockTable value="{!Opportunity.OpportunityContactRoles}" var="cr">
            <apex:column value="{!cr.Contact.Name}"/>
            <apex:column value="{!cr.Role}"/>
        </apex:pageblockTable>
    </apex:pageBlock>
</apex:page>
User-added image
 
This was selected as the best answer
Carole Reynolds1Carole Reynolds1

@Terence_Chiu Thank you so much, based on what you provided I was able to write exactly what I needed. In my scenario there is always only going to be one contact in the contact role on a given opportunity, so I didn't need to worry about the role itself. In the email template the repeat value is done like {!RelatedTo.OpportunityContactRoles}. I didn't know how that translated for this page, and your answer pointed me in the right direction.

<apex:repeat value="{!Opportunity.OpportunityContactRoles}" var="cr">{!cr.Contact.Name}</apex:repeat><br/>

Your help has been greatly appreciated!