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
JeriMorrisJeriMorris 

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.)

 

Thanks!

jhurstjhurst

Jeri,


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}"/>
                </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Hope this helps.

Jay

JeriMorrisJeriMorris

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.

hitesh90hitesh90

Try this,

 

<apex:relatedList list="OpportunityContactRoles" />

 

 

Hope this is helpfull..:)

 

Thanks,

hitesh