I'd like to be able to add / edit Opp. Contact Roles directly from the Opp. view page.
So far I have created a VF page to render the Opp. detail page and a table to allow the updating of the related OppContactRoles.
I have two questions: 1. What would be the best way to add a 'New' button. When clicked, this button would add a new, blank row to the table allowing a new OppContactRole to be added. 2. What is the best way to ensure that only one OppContactRole is set as the primary?
Here is my code:
<apex:page standardController="Opportunity" extensions="OppExtension">
<apex:detail relatedList="false" inlineEdit="true"/>
<apex:form >
<apex:pageBlock title="Opportunity Contacts">
<apex:pageBlockButtons >
<apex:commandButton action="{!quicksave}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!opportunity.opportunitycontactroles}" var="item">
<apex:column title="First Name">
<apex:inputField value="{!item.contact.firstname}"/>
</apex:column>
<apex:column title="Last Name">
<apex:inputField value="{!item.contact.lastname}"/>
</apex:column>
<apex:column title="Role">
<apex:inputField value="{!item.role}"/>
</apex:column>
<apex:column title="Primary Contact?">
<apex:inputField value="{!item.isprimary}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
Extension:
public class OppExtension {
private final Opportunity opp;
public OppExtension (ApexPages.StandardController controller) {
this.opp = (Opportunity)controller.getRecord();
}
}
Also I'm not sure if allowing the users to directly edit the contact.name fields is good practice. Thoughts?
Thanks.