8

I'm experiencing a strange error with Salesforce's Inline Editing in a custom visualforce page. I have a sObject with a date field called Start_Date__c, and I have inline editing set up in the VisualForce like this:

<apex:page standardController="Product_Assignment__c"
    tabStyle="Product_Assignment__c"
    extensions="TestInlineEditControllerExt">

<apex:form id="productForm">
    <apex:pageBlock >
        <apex:pageMessages />
        <apex:pageBlockTable value="{!productAssignments}" var="productAssignment">
            <apex:column headerClass="h1">
                <apex:facet name="header">Start Date</apex:facet>
                <apex:outputField value="{!productAssignment.Start_Date__c}">
                    <apex:inlineEditSupport changedStyleClass="dirtyField" event="ondblclick" showOnEdit="saveChanges" />
                </apex:outputField>
            </apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
    <apex:commandButton id="saveChanges" reRender="productForm" action="{!quicksave}" value="Save Changes" styleClass="saveChangesButton" />
</apex:form>
</apex:page>

The custom controller is as follows:

public with sharing class TestInlineEditControllerExt {
    public List<Product_Assignment__c> productAssignments { get; set; }

    public TestInlineEditControllerExt(ApexPages.StandardController stdController) {
        stdController.addFields(new List<String> { 'Start_Date__c' });
        productAssignments = new List<Product_Assignment__c> {
            (Product_Assignment__c)stdController.getRecord()
        };
    }
}

This works well in normal use cases. If I edit the field an input a deliberately incorrect value (like 'abcdef'), and press save, I receive the expected error: Start Date: Invalid Date and Time.

After this, if I attempt to click the revert button and save again, I receive a cryptic error message: Start Date: Value cannot exceed 0 characters.

I've tried following this pattern on a standard detail page, but this issue only seems to happen on my custom visualforce page. I've also tried using a custom action (instead of "quicksave") on my controller, but have the same issue (error message, controller is never called). We do not have any validation rules in place for this field.

This issue appears to only happen when the page is API version 29. API version 30 produces even stranger results, where the Datepicker does not appear, inline editing only works on the field once (double clicking it again produces no result), and no message appears when trying to save an invalid date (the date just reverts). API version 31 produces similar issues, and an error "There is no record to save" if I try to save an invalid value and revert.

Does anybody know why this is happening and how I can fix this issue?

Edit: Added example controller and full VF to produce this issue

Edit 2: Added details about API version

9
  • I'd expect it would be very helpful if you posted the code to your custom controller. Also, is there a particular format your date field is expecting as in dd/mm/yyyy vs something else?
    – crmprogdev
    Jun 18, 2014 at 17:22
  • Yes, please post your code - I am curious if you are using a custom controller or a standard controller with a custom controller extension. Jun 18, 2014 at 17:53
  • I can't post the exact code I was using, but I added an example that produces the same issue. Product_Assignment__c is the custom object here and has a Start_Date__c Datetime field. Jun 18, 2014 at 18:28
  • Oddly, this error only seems to happen when I have an inline edit control inside of <apex:repeat> or <apex:pageBlockTable>. Unfortunately, I need to deal with a list in my code (even though this example only has a single item in the list), and I will need to use a pageBlockTable Jun 18, 2014 at 19:06
  • Any Solution for this problem so far? I'm having the Same problem. When the Page loads, The Inline Edit is active. But, When i willingly add TEXT in an DATE field, The Standard Error would display which says "INVALID DATE". But, Locks the Inline Edit on the VF Page where i can only have to either REFRESH the page or hit CANCEL. This doesnt happen on Standard Salesforce Pages which is what I'm looking for. Thanks
    – Shri Raj
    Jun 18, 2014 at 20:50

1 Answer 1

4

I was able to replicate your problem and discovered that if you click off before saving the record each time then you wouldn't get the error. The solution below introduces a pause to mimic the user clicking off the field:

<apex:page standardController="Product_Assignment__c"
    tabStyle="Product_Assignment__c"
    extensions="TestInlineEditControllerExt">
    <script>
        function callQuickSave() {
            document.getElementById('saveChanges').focus();
            setTimeout(function(){quicksave();}, 1000)
        }
    </script>
    <apex:form id="productForm">
        <apex:pageBlock mode="inlineEdit">
            <apex:actionFunction name="quicksave" action="{!quicksave}" reRender="productForm"/>
            <apex:pageMessages />
            <apex:pageBlockTable value="{!productAssignments}" var="productAssignment">
                <apex:column headerClass="h1">
                    <apex:facet name="header">Start Date</apex:facet>
                    <apex:outputField value="{!productAssignment.Start_Date__c}">
                        <apex:inlineEditSupport changedStyleClass="dirtyField" event="ondblclick" showOnEdit="secondaryButton" hideOnEdit="editButton" resetFunction="resetInlineEdit"/>
                    </apex:outputField>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <input type="button" id="saveChanges" onclick="callQuickSave()" value="Save Changes" styleClass="saveChangesButton"/>
    </apex:form>
</apex:page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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