Difference between returning null and ApexPages.currentPage()

How is returning null different from returning ApexPages.currentPage() as a result of a controller action?


The major difference is when you return null the constructors defined in the controller class don’t execute.

While if you return whole page the page gets refreshed and constructors get executed only if you have made setRedirect flag set to true.Hence we have an option either to flushout the viewstate or not using this approach.Returning ApexPages.currentPage() will provide us ability to choose set redirect as true or false depending on the business need for the page.

If you are using reRender tags for ajax actions then we prefer null as to avoid whole refresh of page .

Source : Link , Question Author : ipavlic , Answer Author : Mohith Shrivastava

Leave a Comment