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
ColinKenworthyColinKenworthy 

Visualforce inline edit save behaviour inconsistent.

I've created a really simple custom object (Colin__c) with a few text, picklist and checkbox fields. I've created a simple VF page with inline editing on the fields.

Now, depending on what I do between filling in a value in the field and clicking the Save button, it will affect whether the new value is saved or not.

 

 

<apex:page id="P1" standardController="Colin__c" >

    <apex:form id="F1" >
    <apex:sectionHeader title="{!Colin__c.Name}" />

    <apex:PageBlock id="PB1">
        <apex:pageMessages />

        <apex:pageBlockButtons id="PBB" location="both">
            <apex:commandButton id="inlineEditSave"   value="Save"   action="{!save}"   style="display:none"/>
            <apex:commandButton id="inlineEditCancel" value="Cancel" action="{!cancel}" style="display:none"/>
            <apex:commandButton id="editButton"       value="Edit"   action="{!edit}"/>
            <apex:commandButton id="deleteButton"     value="Delete" action="{!delete}" onclick="if ((Modal.confirm && Modal.confirm('Are you sure?')) || (!Modal.confirm && window.confirm('Are you sure?'))) {return true;} else {return false;}"/>
        </apex:pageBlockButtons>

        <apex:pageBlockSection id="PBS" title="Details" columns="2">
        <apex:inlineEditSupport event="ondblclick" showOnEdit="inlineEditSave,inlineEditCancel" hideOnEdit="deleteButton,editButton" resetFunction="resetInlineEdit"/>
            <apex:outputField id="cli02" value="{!Colin__c.Text02__c}"/>     <apex:outputField id="clc02" value="{!Colin__c.Checkbox02__c}"/>
            <apex:outputField id="cli03" value="{!Colin__c.Text03__c}"/>     <apex:outputField id="clc03" value="{!Colin__c.Checkbox03__c}"/>
            <apex:outputField id="cli04" value="{!Colin__c.Text04__c}"/>     <apex:outputField id="clc04" value="{!Colin__c.Checkbox04__c}"/>
            <apex:outputField id="clp01" value="{!Colin__c.Picklist01__c}"/> <apex:outputField id="clp02" value="{!Colin__c.Picklist02__c}"/>
        </apex:pageBlockSection>

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

 

So if I double click on the text field, amend value, hit enter. The text turns orange and I get the undo icon as expected. But when I click Save, the value goes back to its OLD value!

 

If I double click on the text field, amend value, click Save (with the cursor still in the field), the value is updated.

 

 

Why does the way I amend the value affect whether the value saves or not?

It is not the behaviour of inline edit in standard page layouts.

 

Or am I coding my inline edit incorrectly? Can you see anything unusual?

 

Best Answer chosen by Admin (Salesforce Developers) 
Chamil MadusankaChamil Madusanka

Hi Colin,

 

No, there is no any coding error. There seem to still have a problem with the InlineEditSupport component because the example of salesforce doc has the same issue.

 

Check this link

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_inlineEditSupport.htm

 

I have another approach for inline editing in VF. If you want notify me.

 

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.

All Answers

Chamil MadusankaChamil Madusanka

Hi Colin,

 

No, there is no any coding error. There seem to still have a problem with the InlineEditSupport component because the example of salesforce doc has the same issue.

 

Check this link

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_inlineEditSupport.htm

 

I have another approach for inline editing in VF. If you want notify me.

 

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.

This was selected as the best answer
ColinKenworthyColinKenworthy

Hi Chamil,

 

Thanks for the link. I have raised a case (I wrote that it is definitely a bug) with SF through my developer org but I don't know how seriously they look at obvious bugs in VF. I cannot imagine how this got through testing.

 

I have, for now, decided not to use any in-line editing in my VF page as the thought that only half the updated fields on a page might actually be comitted to the database is unacceptable. Perhaps it will be fixed in the next release.

 

regards

Colin.

Chamil MadusankaChamil Madusanka

Hi Colin,

 

I have another approach for inline editing in visualforce page. I will post the example code for Contact object. It will work with custom objects as well.

 

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 >
    <apex:outputPanel id="contactList">
    <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="contactList">Cancel</apex:commandLink></td>
                <td><apex:commandLink action="{!saveEdit}" rerender="contactList">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 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;
    }

}

 

 

 

Try with this.

 

No more unfortunate for inline editing on visualforce pages :smileyhappy:

 

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.

 

 

ColinKenworthyColinKenworthy

Thanks Chamil,

 

I hope people can make use of this.

 

Best Regards.

MikeSFMikeSF
Hi Chamil,
For others looking at this I needed to remove the rerender="employeeList from the edit link to get this to work, but otherwise a great post thanks very much!
Br