0

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">
            <tbody>
                <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">
                            </apex:outputfield>
                        </div>
                        <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:outputfield>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
        <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}" />
        </apex:commandButton>
    </apex:repeat>
</apex:form>

Controller Code:

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

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

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

Update:

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

0

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 -_- – Timothy 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.