I am trying to do inline editing on a vf page with a customController but I can't seem to get any data to pass to the controller on clicking on the save button.

VF Page:

<apex:form id="makeEdit">
    <apex:repeat var="oppProductInfo" value="{!oppLineItems}">
        <table id="lineItemTable">
                <tr class="displayNone">
                    <td colspan="5">
                        <div class="twoColumns" style="height: 61px;">
                            <apex:outputLabel value="Version:" for="picklistHeader" />
                            <br />
                            <apex:outputfield value="{!oppProductInfo.Product2.Version__c}" styleClass="removeDefault picklistHeader" id="picklistHeader">
                        <div class="twoColumns">
                            <apex:outputLabel value="Term: # Years:" for="termYear"/>
                            <br />
                            <apex:outputfield value="{!oppProductInfo.Term_Years__c}" styleClass="removeDefault termYear" id="termYear">
                                <apex:inlineEditSupport showOnEdit="saveEdit, cancelEdit" event="ondblclick" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
        <apex:commandButton id="saveEdit" value="Save Changes" action="{!updateRecord}" rerender="makeEdit" status="updatingRecord" styleClass="newButton floatRight">
            <apex:param name="termYear" value="{!oppProductInfo.Term_Years__c}" assignTo="{!termYear}" />

Controller Code:

public String termYear { get; set; }
public PageReference updateRecord(){
    OpportunityLineItem pli = new OpportunityLineItem();
    pli.Id = curId;
    pli.Term_Years__c = termYear;

        update pli;
        System.debug('Update Successful');
    } catch (Exception e){
        ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, e.getMessage());
    return null;

Would someone mind pushing me in the right direction? I feel I might be doing something really stupid :/


I also debugged "termYear" to the console and it's just showing as the previous value


To create a record you must create a new instance of it when your controller loads. Put the line pli = new OpportunityLineItem(); inside your constructor and set pli as a getter/setter outside your methods. In your page, you can then reference the fields of pli directly (like <apex:inputField value="{!pli.MyField__c}"/>).

If you want to edit a record, I strongly recommend you to query for all the fields in your object in your constructor, and assign it to a public variable, with setter/getter attributes. Then, the rest is pretty much the same I explained above.

Also, I noticed you tried to build a table using HTML, but then, if you need a table for multiple values, consider using <apex:dataTable>. It is easier, in my opinion.

  • 1
    Thanks for this... I worked out I was being silly and lazy loading the Opp and Opp Line Items so it was just querying the data and updating it -_- – Tim Nov 8 '15 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.