You need to sign in to do that
Don't have an account?
Opportunity Contact Role will not save
Hello All:
I'm trying to create an Opportunity detail page in which users may edit related data without going to a separate page. In this instance, I want them to be able to edit Contact Roles. I have written a VF page that looks like this:
<apex:page standardController="Opportunity" tabStyle="Opportunity"> <apex:detail /> <apex:form > <apex:pageBlock title="Change Roles" mode="detail"> <apex:pageMessages /> <apex:pageBlockButtons location="top"> <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:pageBlockTable value="{!Opportunity.OpportunityContactRoles}" var="OC"> <apex:column > <apex:inputfield value="{!OC.Contact.Firstname}"/> </apex:column> <apex:column > <apex:inputfield value="{!OC.Contact.Lastname}"/> </apex:column> <apex:column > <apex:inputfield value="{!OC.IsPrimary}"/> </apex:column> <apex:column > <apex:inputfield value="{!OC.Role}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
However, when I click "Save," none of the information seems to take. What am I missing?
Any help would be appreciated!
Thanks,
Josh
All Answers
Hi Josh,
I had to do something like this recently. My understanding is that the standard save function doesn't provide the functionality to save the updates to a related object. For this you'll have to use a controller extension. You could override the save function to add in logic to update / insert the OpportunityContactRole records then leverage controller.save() (assuming you've setup the page with a variable called controller) to save any changed opportunity fields and to get the page reference of the updated opportunity. Take a look at the following code snippet to get you started:
// Setup the standard controller and class variable for Opportunity
Opportunity opp;
ApexPages.StandardController controller;
public OppEditExtController(ApexPages.StandardController stdController){
this.opp = (Opportunity)stdController.getRecord();
this.controller = stdController;
}
public PageReference save() {
// Write some custom logic here to save the OpportunityContactRole records
PageReference p = controller.save();
// Any other logic you need to add to the page post save
return p;
}
Awesome Stuff sfdcfox !
I'm tasked currently with trying to Add 2 picklists to the ContactRole UI
these are to be added to the already existing "Primary" button, Contact Lookup & Role picklists that are standard to that UI
Any advice on "breaking into" the Contact Role UI and adding custom fields to it?
Desired End Result = in the Contact Role section of Oppty - there would be 2 added columns in the mini layout etc.
Thx in Advance!!!!!!! Client is screaming at me :(
ChazDad
dev@cloudpaasgroup.com