+ Start a Discussion

Show Role in Contact's Opportunities related list

I have Contacts who sometimes have more than one role in an Opportunity, so they have more than one Opportunity Contact Role record. When I'm looking at their Contact page, the Opportunities related list shows the same Opportunity more than once -- it shows once for each Opportunity Contact Role that the Contact has. Is there any way to get the Opportunities related list to show the Opportunity only once, regardless of the number of Opportunity Contact Roles? If not, is there any way to get the related list to display the Role name? (I've looked, and I don't see any way to make that happen.)





To do this you would actually have to create a VF page and (potentially) override teh COntact View.


Apex Controller

public class oppRelatedList {

    public List<OpportunityContactRole> ocr = new OpportunityContactRole[]{};
    public oppRelatedList(ApexPages.StandardController controller) {
        ocr = [select OpportunityId, Opportunity.Name, Opportunity.StageName, Opportunity.Amount, Opportunity.CloseDate, Role 
               from OpportunityContactRole where ContactId = :System.currentPageReference().getParameters().get('id')];

    public List<OpportunityContactRole> getOCR() {
        return ocr;


VF Page

<apex:page standardController="Contact" extensions="oppRelatedList">
    <apex:detail relatedList="false"/> 
    <apex:form >
        <apex:pageBlock id="thePageBlock" title="Opportunities">
            <apex:pageBlockTable value="{!OCR}" var="o" >
                <apex:column headerValue="Opportunity Name"><apex:outputLink value="/{!o.OpportunityId}" id="theLink">{!o.Opportunity.Name}</apex:outputLink></apex:column>
                <apex:column headerValue="Stage" value="{!o.Opportunity.StageName}"/>
                <apex:column headerValue="Amount" value="{!o.Opportunity.Amount}"/>
                <apex:column headerValue="Close Date" value="{!o.Opportunity.CloseDate}"/>
                <apex:column headerValue="Role" value="{!o.Role}"/>


Hope this helps.



Thanks. I knew I could do this with Visualforce and Apex, but was hoping there was a more standard, code-free way of doing it.


Try this,


<apex:relatedList list="OpportunityContactRoles" />



Hope this is helpfull..:)