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
avimeiravimeir 

Database update takes long to show in GUI

Hi,

 

I have a custom object called Reservation__c that has a picklist Status__c.

 

I've created a custom button from the detail page that opens a new window to a custom VF page, where the user can change attributes of Reservation__c. On that page, the user can click Save, which does APEX update to the relevant Reservation__c object and window.top.close() to return to the Reservation__c detail page. Once the window is closed, I do a JS refresh of the Reservation__c page to show the changes of the object.

 

The problem is that it takes a few seconds for the change of Status__c to be seen in the Reservation__c page. I suspect that this is due to a delay in the database write backlog. If I wait 2-3 seconds and then manually refresh, the correct changes can be seen. 

 

Any idea on how to solve this issue?  I want the changes to be shown after the automatic refresh, and I want this automatic refresh to be done as soon as the database is updated.

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

It should be available "immediately" unless you're using @future methods (which are still generally immediate). Are you calling window.top.close() on submit on on complete? Once the page is fully rerendered, the data should be immediately available. If you're closing/refreshing "on submit", then the transaction is still running by the time the page reloads. Any synchronous calls are fully committed when they return. In fact, we have code like this in our project, and it works beautifully. Here's the basic idea:

 

<!-- CloseRefresh.page -->
<apex:page>
<script>
window.top.opener.refresh();
window.top.close();
</script>

<!-- OtherPage.page -->
<apex:page controller="xyz">
<apex:form>
  <apex:commandButton value="Save/Close" action="{!saveClose}"/>
  <!-- more form stuff here, etc -->
</apex:form>
</apex:page>

// xyz.cls
public with sharing class xyz {
  public PageReference saveClose() {
    // Save, and if all is well, return:
    return Page.CloseRefresh;
  }
}

If you follow this design, the commits will be visible by the time the window closes.

All Answers

sfdcfoxsfdcfox

It should be available "immediately" unless you're using @future methods (which are still generally immediate). Are you calling window.top.close() on submit on on complete? Once the page is fully rerendered, the data should be immediately available. If you're closing/refreshing "on submit", then the transaction is still running by the time the page reloads. Any synchronous calls are fully committed when they return. In fact, we have code like this in our project, and it works beautifully. Here's the basic idea:

 

<!-- CloseRefresh.page -->
<apex:page>
<script>
window.top.opener.refresh();
window.top.close();
</script>

<!-- OtherPage.page -->
<apex:page controller="xyz">
<apex:form>
  <apex:commandButton value="Save/Close" action="{!saveClose}"/>
  <!-- more form stuff here, etc -->
</apex:form>
</apex:page>

// xyz.cls
public with sharing class xyz {
  public PageReference saveClose() {
    // Save, and if all is well, return:
    return Page.CloseRefresh;
  }
}

If you follow this design, the commits will be visible by the time the window closes.

This was selected as the best answer
avimeiravimeir

I was actually using onclick instead of oncomplete.... Thanks!!