2

I am displaying custom object records in a datatable. I modify the data using the Salesforce API (i.e. outside the current page), and then when the user clicks a button I want to rerender the datatable and show the changes.

The problem I have is that the rerender does not pick up the changes, it shows the old data. Reloading the whole page does pick up the changes. Here is the code:

    <apex:form>
        <apex:actionFunction name="rerenderMyPanel" rerender="MyPanel" />
    </apex:form>
    <apex:outputPanel id="MyPanel" styleClass="pbBody" layout="block">
        <apex:dataTable value="{!Account.MyCustomObject__r}" var="item" styleClass="list">
            ... datatable here.

        </apex:dataTable> 
    </apex:outputPanel>

I am sure my rerender is working because I can see the table being returned in the Chrome network tab. I also know that a race condition isn't the problem because even after making multiple edits the data via the API, re-rendering doesn't pick up the changes.

I suspect the problem is that the data from Account.MyCustomObject__r is stored in the view state and so doesn't change in the re-render. But I can't work out how to tell Salesforce to use the data stored in the DB during the re-render.

1

Looks like you're using the standard controller:

<apex:page standardController="Account" ...>

When you use the standard controller, it only loads the data once, when the page first loads.

You'll need to use a different technique, such as client-side rendering (e.g. apex:remoteObjects), reloading the page entirely, or writing a custom extension in Apex code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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