Activity Forums Salesforce® Discussions What is the difference between returning null and returning ApexPages.currentPage()?

  • Ajay Prakash

    Member
    April 30, 2016 at 3:27 pm

    @Himanshu

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

    Thanks

     

  • Parul

    Member
    September 12, 2018 at 4:23 pm

    Hello Himanshu,

    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 .

    Thanks.!

  • shariq

    Member
    September 14, 2018 at 5:12 am

    Hi,

    For more information, Returning the current page won't run the constructors unless the setRedirect flag is set to true though. From the docs "If the postback request indicates a page redirect and the redirect is to a page that uses the same controller and a proper subset of controller extensions of the originating page, a postback request is executed for that page." In this case, the same controller would be in use as its the same page.

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos