+ Start a Discussion
Kerry ProkselKerry Proksel 

Editing Opportunity Line Items with VisualForce - Won't Save

I'm trying to create a VF page that will allow the sales team to edit multiple opportunity line items at the same time. My work compiles fine, but the save button doesn't actually edit any of the products. Anyone know what I'm doing wrong?

VF:
<apex:page standardController="Opportunity" extensions="OLIController" >
    <apex:form >
        <apex:pageBlock title="Opportunity Products">
            <apex:pageBlockTable var="OLI" value="{!OLIs}" id="newProduct">
                <apex:column value="{!OLI.name}"/>
                <apex:column headerValue="Product Family">
                    <apex:inputfield id="Product_Family__c" value="{!OLI.Product_Family__c}"/>
                </apex:column>
                <apex:column headerValue="Product Included in Sale">
                    <apex:inputfield id="Product_Included_in_Sale__c" value="{!OLI.Product_Included_in_Sale__c}"/>
                </apex:column> 
                <apex:column headerValue="Product Lost Reasons">
                    <apex:inputfield id="Product_Lost_Reasons__c" value="{!OLI.Product_Lost_Reasons__c}"/>
                </apex:column> 
                <apex:column headerValue="Product Gap Reason">
                    <apex:inputfield id="Product_Gap_Reason__c" value="{!OLI.Product_Gap_Reason__c}"/>
                </apex:column> 
                <apex:column headerValue="Competitor">
                    <apex:inputfield id="Competitor__c" value="{!OLI.Competitor__c}"/>
                </apex:column> 
            </apex:pageBlockTable>
            <apex:pageBlockButtons>
                <apex:commandButton value="Save" action="{!saveIt}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public with sharing class OLIController {

public ApexPages.StandardController sc;
public Opportunity Opp {get;set;}
public List<OpportunityLineItem> OLIlist2 {get ;set;}

public OLIController(ApexPages.StandardController sc) { 
this.Opp = (Opportunity)sc.getRecord();
OLIlist2 = [Select Name, ID, Product_Family__c, Product_Included_in_Sale__c, Product_Lost_Reasons__c, Product_Gap_Reason__c, Competitor__c, OpportunityId FROM OpportunityLineItem WHERE OpportunityId =:Opp.Id];
}


public List<OpportunityLineItem> getOLIs() {

    List<OpportunityLineItem> OLIlist2 = [Select Name, ID, Product_Family__c, Product_Included_in_Sale__c, Product_Lost_Reasons__c, Product_Gap_Reason__c, Competitor__c, OpportunityId FROM OpportunityLineItem WHERE OpportunityId =:Opp.Id];

    return OLIlist2;

}
public PageReference saveIt() {
   // List<OpportunityLineItem> listOLI = getOLIs();

    update OLIlist2;

    return null;

}
}
Best Answer chosen by Kerry Proksel
Alain CabonAlain Cabon
Hi,

You are using OLIs in the VFP and OLIlist2 in the controller.

apex:pageBlockTable var="OLI" value="{!OLIs}" id="newProduct">
 <apex:inputfield id="Product_Family__c" value="{!OLI.Product_Family__c}"/>

public List<OpportunityLineItem> getOLIs() {  // but you update OLIlist2

public List<OpportunityLineItem> OLIlist2 {get ;set;}
update OLIlist2;

You must choose only one list of OpportunityLineItem (OLIs  or OLIlist2) for the VFP and the Apex controller.

All Answers

Alain CabonAlain Cabon
Hi,

You are using OLIs in the VFP and OLIlist2 in the controller.

apex:pageBlockTable var="OLI" value="{!OLIs}" id="newProduct">
 <apex:inputfield id="Product_Family__c" value="{!OLI.Product_Family__c}"/>

public List<OpportunityLineItem> getOLIs() {  // but you update OLIlist2

public List<OpportunityLineItem> OLIlist2 {get ;set;}
update OLIlist2;

You must choose only one list of OpportunityLineItem (OLIs  or OLIlist2) for the VFP and the Apex controller.
This was selected as the best answer
Kerry ProkselKerry Proksel
OK thanks that worked!