+ Start a Discussion
JoséTlasecaJoséTlaseca 

Visualforce Pages using SetRedirect(true) in Force.com sites

Hello community!

I always try to solve issues by myself, but this time i have tried several things and i can't fix it. Here we go:

I have created several VF pages and controllers that interact between each other by PageReference methods.

Lets say We have 2 pages and 2 controllers:

ContactsListPage => ContactsListPageController
ContactDetailPage => ContactDetailPageController

ContactsListPage shows a table with records with a commandButton each, this way user can edit the desired record. The edit action invokes EditRecord() method from ContactsListPageController, which creates a page reference and adds some query strings to it to know which contact was selected.
Then ContactDetailPage is invoked and shows the edit form and a Save command button. This button invokes SaveRecord from ContactDetailPageController. This method does a setRedirect(true) to the pageReference in order to force the ContactsListPage to show the changes made by the user in the list of contacts.

Something like this:

ContactsListPageController
{
    ...
    PageReference EditRecord()
    {
        ...
        PageReference page = new PageReference('apex/ContactDetailPage?recordId=' + someId);
        page.setRedirect(true);
        return page;
    }
}


ContactDetailPageController
{
    ...
    PageReference SaveRecord()
    {
        update record;
        ...
        PageReference page = new PageReference('apex/ContactsListPage');
        page.setRedirect(true); //To preserve viewstate vars and force ContactsListPage to show the changes
        return page;
    }
}



This works perfect from inside salesforce, I mean, invoking VF pages by adding /apex/ContactsListPage to the URL to show the first page.

Well, the problem is that those app are needed to be shown using a force.com Site, and there the setRedirect seems not to work. The changes made by the user in the contact detail page are not reflected to the contacts list page when it is saved unless user manually refreshes the page with the browser button of hitting F5.
All the changes are well saved to Salesforce, the problem is only in the UI, it is not refreshing.

The weird thing is that it works as it should if i don't use Sites.

Any idea what is causing this and how to dolve it?

Any comment is welcome.

Regards!
Best Answer chosen by JoséTlaseca
ShaTShaT
Hi ,

I think you need to make cache="false" than it wolud work.
eg-
<apex:page Controller="ContactRolesList" sidebar="false" showheader="false" tabstyle="Contact" cache="false" >

Thanks
Shailu

All Answers

ShaTShaT
Hi ,

I think you need to make cache="false" than it wolud work.
eg-
<apex:page Controller="ContactRolesList" sidebar="false" showheader="false" tabstyle="Contact" cache="false" >

Thanks
Shailu
This was selected as the best answer
JoséTlasecaJoséTlaseca
Shailu:

Thank you so much. that did the trick. Really appreciate it.

Have a nice day!