[SalesForce] Inline edit of PageBlockTable only saving one record

Ive added an inline VF page to an Event standard layout that displays a list from a related custom object. The aim is to create a false lookup relationship to get round not being able to create one normally in Events. All works fine, except when inline editing the pageblocktable. When updating multiple rows in the pageblocktable, only one record is saved and the others revert to what they were before. Any ideas? Code below:

controller

public class AttendeesInlineController {
public string eventId;
public List<Attendee__c> attended {get;set;}

public AttendeesInlineController() {

}

private ApexPages.StandardController controller {get; set;}
private Event e;


public AttendeesInlineController(ApexPages.StandardController controller)
{
    //initialize the stanrdard controller
    this.controller = controller;
    this.e = (Event)controller.getRecord();
    eventId = e.Id;
    system.debug('EEEEEEEEEEEEEEE - ' + e.Id);
    RefreshAttendees(); 
}

public void RefreshAttendees()
{
    attended = [Select Id, Client__c, EventID__c, Attended__c from Attendee__c where EventID__c =:eventId];
}

public PageReference AddAttendees()
{
    PageReference pr = Page.EventAttendees;
    pr.getParameters().put('EventId',eventId);
    return pr.setRedirect(true);    
}

public PageReference SaveInlineChanges()
{
    system.debug(attended);
    update attended;
    return ApexPages.CurrentPage();
}
}

VF

<apex:page standardController="Event" extensions="AttendeesInlineController">
<apex:form >
  <apex:pageBlock >
  <apex:pageblockButtons location="top">
      <apex:commandButton action="{!AddAttendees}" value="Add Attendees" />
      <apex:commandButton action="{!SaveInlineChanges}" value="Save" id="saveButton"/>
      <apex:commandButton action="{!CancelInlineChanges}" value="Cancel" id="cancelButton"/>
  </apex:pageblockButtons>
     <apex:pageBlockTable value="{!attended}" var="attendee">
         <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" 
                        hideOnEdit="editButton" event="ondblclick" 
                        changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
         <apex:column value="{!attendee.Client__c}"/>
         <apex:column value="{!attendee.Attended__c}"/>
     </apex:pageBlockTable>
  </apex:pageBlock>
</apex:form>
</apex:page>

Best Answer

Instead of using the "column value" method of defining the records, use the column to render an outputfield, like this:

<apex:pageBlockTable value="{!attended}" var="attendee">
     <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" 
                    hideOnEdit="editButton" event="ondblclick" 
                    changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
     <apex:column headerValue="Client">
         <apex:outputfield value="{!attendee.Client__c}"/>
     </apex:column>
     <apex:column headerValue="Attended">
         <apex:outputfield value="{!attendee.Attended__c}"/>
     </apex:column>
 </apex:pageBlockTable>

You may also want to add the inlineeditsupport into each of the Output fields to get more granular support.

Related Topic