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
juysolutionsjuysolutions 

Platform Bug when rerendering a PageBlockTable with InputFields

I built a page/controller where Users can Add, Edit and Delete rows to a Custom Object in Salesforce. It is very straightforward as shown below:

Platform Bug when rerendering a PageBlockTable with InputFields

Everything works fine except when the User deletes a record in between. Below I deleted the 3rd row "Furniture/Millwork" and notice that the 'Level 2' and 'Level 3' columns changed for the last row "Local Costs".

Platform Bug when rerendering a PageBlockTable with InputFields

What's even odd about this is that these are dependent picklists - meaning, that the "Local Costs" as 'Level 1' SHOULD NOT even have "Site Preparation" as 'Level 2' NOR even have "Hoarding" as 'Level 3'.

I noticed a similar bug when there is a Lookup Field on the page. The whole row gets deleted except for the Lookup Input field.

Does anybody have a similar problem? A Senior Architect may be able to help and explain what caused the problem. Please feel free to request for the code if you can't replicate the issue on your own project.
Best Answer chosen by juysolutions
juysolutionsjuysolutions
Finally here's a statement from the Salesforce representative about the issue:

As discussed over the case, TIER 3 mentioned that the immediate WAD statement is still the same, as you also confirmed the behavior.
"When immediate=true, the post data are not saved in the model on server side." which is the cause of the issue that they are seeing.
"It has been found that the issue was caused by the "immediate" attribute. It has been reported and hopefully this will get fixed.
It would need this attribute to allow Users to remove rows from the page without committing to the server."
At this point we know the issue is caused by the immediate=true parameter per you and we know that the reason for the picklists not saving between removal is because of the lack of server side commit which you doesn't want so this is WAD and won't work in that way. For now, you can consider the workarounds discussed previously.

Hopefully, this gets fixed!

All Answers

KevinPKevinP
I suspect you're relying on field defaults, rather than setting values of the picklists for defaults. (sublte difference) and as a result, when the page blocktable is re-rendered, the "applicable" default is calculated and returns a different value.

I'd be able to help more if you posted the code.
juysolutionsjuysolutions
Hi KevinP,

Field defaults are "-None-". What you actually see on the screenshots are values set and saved. The following are excerpts of the code:

<!-- PAGE -->
<apex:pageBlockTable value="{!objList}" var="item">
        <apex:column style="text-align:center;">
            <apex:commandLink action="{!delRow}" immediate="true" reRender="pgBlk" status="processStatus">
                <apex:image url="/img/func_icons/remove12_on.gif" title="Remove Row"/>
                <apex:param name="index" value="{!counter}"/>
            </apex:commandLink>
            <apex:variable var="counter" value="{!counter+1}"/>
        </apex:column>
        <apex:column >
            <apex:inputField value="{!item.obj['Level_1__c']}"/>
        </apex:column>
        <apex:column >
            <apex:inputField value="{!item.obj['Level_2__c']}"/>
        </apex:column>
        <apex:column >
            <apex:inputField value="{!item.obj['Level_3__c']}"/>
        </apex:column>
</apex:pageBlockTable>

/*** CONTROLLER ***/
public void delRow(){
        Integer index = Integer.valueOf(ApexPages.currentPage().getParameters().get('index'));
        delRow(index);
}
    
private void delRow(Integer index){
        if(objList[index].objId!=null)
            delObjs.add(objList[index].obj);

        objList.remove(index);
}

I've escalated this issue to SF Support and they are looking at it right now but any expert feedback would be appreciated! =)

KevinPKevinP
Out of curiosity, have tried using field-type specific input fields? ie: apex:inputText or apex:inputCheckbox ?
juysolutionsjuysolutions
No, since these are dependent picklists.
juysolutionsjuysolutions
UPDATE (after 3 days): SF Support just escalated this to Tier 3. Let's hope they get back on something.
juysolutionsjuysolutions
UPDATE: I'm still waiting for an update from Tier 3 but I think they don't exist. Although I'm probably lucky enough to get in touch with real person and not just a computer operated person like Siri. Anyhoo, further to my investigation, I found that the issue was caused by the "immediate" attribute. I reported this back the Case and hopefully this will get fixed. I would need this attribute to allow Users to remove rows from the page without committing to the server. It's a pitty that no one has a similar issue like mine. Would be great if good Architects out there can take a look at this issue.
juysolutionsjuysolutions
Finally here's a statement from the Salesforce representative about the issue:

As discussed over the case, TIER 3 mentioned that the immediate WAD statement is still the same, as you also confirmed the behavior.
"When immediate=true, the post data are not saved in the model on server side." which is the cause of the issue that they are seeing.
"It has been found that the issue was caused by the "immediate" attribute. It has been reported and hopefully this will get fixed.
It would need this attribute to allow Users to remove rows from the page without committing to the server."
At this point we know the issue is caused by the immediate=true parameter per you and we know that the reason for the picklists not saving between removal is because of the lack of server side commit which you doesn't want so this is WAD and won't work in that way. For now, you can consider the workarounds discussed previously.

Hopefully, this gets fixed!
This was selected as the best answer