function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KVaishnaKVaishna 

Inline edit for multiple records

Hi,

 

I have custom list which I am displaying in VF inside page block. I have enabled inline editing so that users can edit any record in the list and save the changes.

 

But any changes to only last record in the list are getting saved. Inline changes to any other record in the list are not getting saved.

 

I tried both the following options for inline editing...

 

<apex:pageBlock mode="inlineEdit">

 <apex:inlineEditingSupport> component

 

Is this the expected behavior? Is there any solution/workaround to this?

 

Thanks & Regards,

-Kunjan

Chamil MadusankaChamil Madusanka

Hi,

 

I have an approach for your requirement. Try this example which related to Contact object.

 

Visualforce page

 

<apex:page sidebar="false" controller="InlineController"> 
    
  <!--  <apex:sectionHeader title="Edit Employees" subtitle="{!$User.FirstName} {!$User.LastName}"/>-->
    <p/>
    
    <apex:pageMessages />
    <apex:form >    
    
    <apex:actionFunction name="saveEdit" action="{!saveEdit}"/>
    
 <!-- <apex:pageBlock title="New Contact">
   <apex:pageBlockSection columns="4">
       <apex:pageBlockSectionItem >
           <apex:outputLabel value="Last Name" for="lastname"></apex:outputLabel>
          <apex:inputField id="lastname" value="{!newContact.LastName}" /> 
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem > 
            <apex:outputLabel value="Email" for="email"></apex:outputLabel>
           <apex:inputField id="email" value="{!newContact.email}"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Employee" for="empId"></apex:outputLabel>
            <apex:inputField id="empId" value="{!newContact.Employee__c}"/>  
        </apex:pageBlockSectionItem>
        
        <apex:pageBlockSectionItem >
        <apex:commandButton value="Add" action="{!add}"/>
       </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock> -->
    
    <apex:pageBlock >
    <apex:outputPanel id="employeeList">
    <table>
        <tr>
            <th style="width:40px"> </th>
            <th style="width:40px"> </th>
            <th style="width:90px">Last Name</th>
            <th style="width:90px">Email</th>
            <th>Mailing Country</th>
        </tr>
        <apex:repeat value="{!employees}" var="e">
        <tr style="height:20px">
            <apex:outputPanel id="editRow" layout="none" rendered="{!e.Id == editContact.Id}">
                <td><apex:commandLink action="{!cancelEdit}" rerender="employeeList">Cancel</apex:commandLink></td>
                <td><apex:commandLink action="{!saveEdit}" rerender="employeeList">Save</apex:commandLink></td>
                <td><apex:inputField rendered="{!e.Id == editContact.Id}" value="{!editContact.LastName}"/></td>
                <td><apex:inputField rendered="{!e.Id == editContact.Id}" value="{!editContact.email}"/></td>
             <td><apex:inputField rendered="{!e.Id == editContact.Id}" onkeypress="if (event.keyCode == 13) saveEdit()" value="{!editContact.MailingCountry}"/></td>
            </apex:outputPanel>
            <apex:outputPanel id="viewRow" layout="none" rendered="{!e.Id != editContact.Id}">
                <td>
                    <apex:commandLink action="{!del}" onclick="return confirm('Are you sure you want to delete this Employee?')">Del
                        <apex:param name="delid" value="{!e.Id}"/>
                    </apex:commandLink>
                    
                </td>
                <td>
                    <apex:commandLink action="{!editcon}" rerender="employeeList">Edit <apex:param name="editid" value="{!e.id}"/>
                    </apex:commandLink>
                </td>
                <td>{!e.LastName}</td>
                <td>{!e.email}</td>
                <td>{!e.MailingCountry}</td>
            </apex:outputPanel>
        </tr>
        </apex:repeat>
    </table>
    </apex:outputPanel>
    </apex:pageBlock>

    </apex:form>
    
</apex:page>

 Controller

 

public class InlineController {


    public InlineController(ApexPages.StandardController controller) {
    
    }



   public Contact newContact { get; set; }
    
    public Contact editContact { get; set; }

    public InlineController () {
        newContact = new Contact();
    }
    
    public Contact[] getEmployees() {
        return [Select c.MailingCountry, c.LastName, c.Id, c.Email From Contact c];
    }
    
    public String getParam(String name) {
        return ApexPages.currentPage().getParameters().get(name);   
    }
    
    public PageReference add() {
        try {
            INSERT newContact;
            newContact = new Contact();
        } catch (Exception e) {
            ApexPages.addMessages(e);
        }
        return null;
    }
     
    public PageReference del() {
        try {
            String delid = getParam('delid');
            Contact employee = [SELECT Id FROM Contact WHERE ID=:delid];
            DELETE employee;
        } catch (Exception e) {
            ApexPages.addMessages(e);
        }
        return null;
    }
    
    public PageReference editcon() {
        String editid = getParam('editid');
        editContact = [SELECT Name, LastName, email,MailingCountry FROM Contact WHERE id=:editid];
        return null;
    }
    
    public PageReference cancelEdit() {
   // System.Debug('GETURL ::: '+ApexPages.currentPage().getUrl());
        editContact = null;
        return null;
    }
    
    public PageReference saveEdit() {
        try {
            UPDATE editContact;
            editContact = null;
        } catch (Exception e) {
            ApexPages.addMessages(e);
        }
        return null;
    }

}

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

 

 

Sonali BhardwajSonali Bhardwaj

try

Page:

 

<apex:form>
 <apex:pageBlock>
 <apex:repeat value="{!acc}" var="a">
 <apex:outputfield value="{!a.name}">
 <apex:inlineEditSupport/>
 </apex:outputfield>
 </apex:repeat >
  
 </apex:pageBlock>
 <apex:commandButton value="Save" action="{!save}"/>
 </apex:form>

 

 

Class:

 

// Get list of accounts in constructor.

public void save() { update acc; }

 

 

KVaishnaKVaishna

Hi Chamil,

 

Thanks for the code. Let me look how can I make changes in my code using this.

 

I want to achieve it with inlineEditsupport on double click of the page. similar to standard Salesforce view with inline editing.

 

Thanks,

-Kunjan

KVaishnaKVaishna

Thanks for the code Sonali.

 

Yes outputfield works when I use it with pageblock mode='inlineEdit'. using  <apex:inlineEditSupport/> throws me some javascript errors may be due to integration with other custom components.

Not sure why it does not work with apex:column.

 

I am using lot of custom components for pagination, sorting and other functionalities so I will have to check how this will impact the overall integration with other components.

 

Thanks,

-Kunjan

 

Chamil MadusankaChamil Madusanka

Hi Kunjan,,

 

Then Try this example from my blog.

http://salesforceworld.blogspot.com/2011/06/inline-editing-in-visualforce-page.html

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

KVaishnaKVaishna

Thanks for the code Chamil.

 

I am not sure what is significance of <apex:inlineEditSupport event="ondblclick"/> because inline editing is enabled using <apex:pageBlock id="subPageBlock" mode="inlineEdit"> so why do we need <apex:inlineEditSupport event="ondblclick"/>  tag at all..

 

I am also looking at way to have dependent picklists and lock certain fields from inline editing. I thought with using <apex:inlineEditSupport event="ondblclick"/> you can enable inline edit only on certain field and not on entire block but that's not the case..!!

 

Thanks & Regards,

-Kunjan

Chamil MadusankaChamil Madusanka

Hi Kunjan,

 

Yeah without <apex:inlineEditSupport event="ondblclick"/>, it works properly. I'll check on it. Was my post healpful for you?

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

Chamil's Blog

Chamil MadusankaChamil Madusanka

Hi,

 

Here some details about inlineedit support

 

http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_quick_start_inline_editing.htm#kanchor123

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

Chamil's Blog

KVaishnaKVaishna

Hi Chamil,

 

Yes your blog was useful. Thanks for link as well.

 

Basically I will have to use mix of OutputField, OutputText to get what I am looking for..

 

Thanks again.

-Kunjan