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
Janis Davis 22Janis Davis 22 

Customize the Contact Roles related list fields on Opportunities with VF Question

I needed to be able to customize the fields visible on the Contact Role Opportunity related list to add the Contact Mobile Phone. I searched Answers and the famous Deepak came up with a brillant work-around solution using VisualForce (see link to the original thread below).

https://success.salesforce.com/answers?id=90630000000hp0AAAQ

I used the VF code he provided and modified it to pull in the Contact Mobile Phone into the Contact Roles related list on the Opportunity. It works perfectly except for a couple of things:
  • When I click to add a New Contact Role in the new VF page on the Opportunity, it pulls it in within the full SF tab and sidebar window (see screen shot below).
  • There is no link to the Contact record in the VF Contact Role related list (see screen shot below).
Add New Contact Role Opens in the full SF tab and sidebar window Shot
User-added image

VF Contact Role has no link to the Contact record​
User-added image


Does anyone know if is there a way to modify the VF code Deepak provided to resolve these two issues? 

Any help or advice will be most appreciated!

Thanks!
 
Best Answer chosen by Janis Davis 22
@Karanraj@Karanraj
Check this updated code which will resolve your two issues
<apex:page standardController="Opportunity">
    <apex:form >
        <apex:pageBlock title="Contact Roles"
            mode="edit" 
            helpTitle="Contact Roles Help"
            helpUrl="https://help.salesforce.com/htviewhelpdoc?id=contactroles_edit.htm">
            <apex:pageBlockTable value="{!Opportunity.OpportunityContactRoles}" var="ContactRole">
                <apex:column >
                    <apex:facet name="header">
                        Action
                    </apex:facet>
                    <a href="/p/opp/ContactRoleEditUi/e?oppid={!Opportunity.Id}&retURL=%2F{!Opportunity.Id}" target="_top">Edit</a>
                </apex:column>
                <apex:column >
                    <apex:facet name="header"> Contact Name </apex:facet>
                    <a href="/{!ContactRole.Contact.Id}" target="_top">{!ContactRole.Contact.Name} </a>
                </apex:column>
                <apex:column value="{!ContactRole.Contact.Account.Name}" headerValue="Account Name"/>
                <apex:column value="{!ContactRole.Contact.Email}" headerValue="Email"/>
                <apex:column value="{!ContactRole.Contact.Phone}" headerValue="Phone"/>
                <apex:column value="{!ContactRole.Role}" headerValue="Role"/>
                <apex:column value="{!ContactRole.Contact.Account.BillingCity},{!ContactRole.Contact.Account.BillingState},{!ContactRole.Contact.Account.BillingCountry}" headerValue="Bill To"/>
                <apex:column value="{!ContactRole.Contact.MailingCity},{!ContactRole.Contact.MailingState},{!ContactRole.Contact.MailingCountry}" headerValue="Ship To"/>                
                <apex:column value="{!ContactRole.IsPrimary}" headerValue="Is Primary"/>
            </apex:pageBlockTable>    
            <apex:pageBlockButtons location="top">
                <input type="button" class="btn" value="New" onclick="javascript:window.open('/p/opp/ContactRoleEditUi/e?oppid={!Opportunity.Id}&retURL=%2F{!Opportunity.Id}');"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>    
    </apex:form>
</apex:page>

 

All Answers

@Karanraj@Karanraj
Check this updated code which will resolve your two issues
<apex:page standardController="Opportunity">
    <apex:form >
        <apex:pageBlock title="Contact Roles"
            mode="edit" 
            helpTitle="Contact Roles Help"
            helpUrl="https://help.salesforce.com/htviewhelpdoc?id=contactroles_edit.htm">
            <apex:pageBlockTable value="{!Opportunity.OpportunityContactRoles}" var="ContactRole">
                <apex:column >
                    <apex:facet name="header">
                        Action
                    </apex:facet>
                    <a href="/p/opp/ContactRoleEditUi/e?oppid={!Opportunity.Id}&retURL=%2F{!Opportunity.Id}" target="_top">Edit</a>
                </apex:column>
                <apex:column >
                    <apex:facet name="header"> Contact Name </apex:facet>
                    <a href="/{!ContactRole.Contact.Id}" target="_top">{!ContactRole.Contact.Name} </a>
                </apex:column>
                <apex:column value="{!ContactRole.Contact.Account.Name}" headerValue="Account Name"/>
                <apex:column value="{!ContactRole.Contact.Email}" headerValue="Email"/>
                <apex:column value="{!ContactRole.Contact.Phone}" headerValue="Phone"/>
                <apex:column value="{!ContactRole.Role}" headerValue="Role"/>
                <apex:column value="{!ContactRole.Contact.Account.BillingCity},{!ContactRole.Contact.Account.BillingState},{!ContactRole.Contact.Account.BillingCountry}" headerValue="Bill To"/>
                <apex:column value="{!ContactRole.Contact.MailingCity},{!ContactRole.Contact.MailingState},{!ContactRole.Contact.MailingCountry}" headerValue="Ship To"/>                
                <apex:column value="{!ContactRole.IsPrimary}" headerValue="Is Primary"/>
            </apex:pageBlockTable>    
            <apex:pageBlockButtons location="top">
                <input type="button" class="btn" value="New" onclick="javascript:window.open('/p/opp/ContactRoleEditUi/e?oppid={!Opportunity.Id}&retURL=%2F{!Opportunity.Id}');"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>    
    </apex:form>
</apex:page>

 
This was selected as the best answer
Janis Davis 22Janis Davis 22
Thank you Karanrajs - you ROCK!!! Works like a charm :-)

Janis
Janis Davis 22Janis Davis 22
@Karanrajs - Hi there again. I now need to add the Del function to my VF Contact Roles page. I tried playing around with code a bit and I got the Del link to show up, however it gives the URL not found error. 

User-added image

Karanrajs - can you or someone else on this community show me the correct code for this?

Any help or advice will be most appreciated!

Thanks!
Sunita PSunita P
Hey Janis,

Did you get the Del link working? I'm trying to implement a similar functionality.

Thank you.
Sunita PSunita P
Hey Janis,

I was able to create the Del link by writing a controller extension.

@Karanraj,
For the href="/p/opp/ContactRoleEditUi/e?oppid={!Opportunity.Id}&retURL=%2F{!Opportunity.Id}", can this be replaced with !URLFOR($Action.Opportunity.edit, ContactRole.id)?

 
Cassie RatliffCassie Ratliff
When I click the "New" button in Salesforce Classic, the VF page works perfectly, but when I do the same in Lightning, the section just goes blank. Any suggestions?
Pablo SchencmanPablo Schencman
Hi Karanrajs,

Your code is great, that you for it!

I have an additional question... our org has several Contact duplicates and it would be very helpfull to see the email addresses on the new Contact Role page...

User-added image

Any way that you can help me with that?

Best and thanks...
Paige PoseyPaige Posey
Cassie Ratliff, did you get this to work in Lightning? I am having the same issue. When I click the "New" button in Salesforce Classic, the VF page works perfectly, but when I do the same in Lightning, the section just goes blank.