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
dwwrightdwwright 

Refreshing Values on a VF Page

I'm building a visualforce page into a form which my users will fill out. The form will have to be regularly saved, and sometimes certain values will cause formula fields on my page to change. The problem is that my controller save method returns ApexPages.currentPage() and when this happens, changes to the formula fields are not reflected until you navigate away from the page and back to it. Is there a way to return a page from my save method such that these formula fields will be displayed with their updated values?
Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard
It may be that the object needs to be pulled anew from the database to update the formula fields.  If that is the case, you could capture ApexPages.currentPage() into a new PageReference, add the id of the object you are managing into the parameters for the page and set the redirect attribute to true.  That will cause a client-side redirect which will build the page from scratch.

All Answers

jdlforcejdlforce
What happens if you do a return null?
bob_buzzardbob_buzzard
It may be that the object needs to be pulled anew from the database to update the formula fields.  If that is the case, you could capture ApexPages.currentPage() into a new PageReference, add the id of the object you are managing into the parameters for the page and set the redirect attribute to true.  That will cause a client-side redirect which will build the page from scratch.
This was selected as the best answer
dwwrightdwwright
All I had to do was setRedirect(true) before returning ApexPages.currentPage(). Many thanks Bob!