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
DaveHDaveH 

Odd redirect behavior on a force.com site

Hey all,

 

I am very familiar wth Visualforce but this is my first time developing a Force.com site and an external page. I have a page that displays information about a custom object (Subscription__c). The details of the object aren't important. Now, the start page for a user to change their preferences is actually a redirect page. It checks for an id specified in the URL parameters and if it is supplied and valid the user is redirected to a second page. When I tested the page internally (with the URL /apex/MyPageName) everything works fine, the CSS looks good, the fields are all filled out with the data from the object ... etc. However, when I try to access the page externally using the domain name I lose all the CSS styling, the static resources (like any images) and also the fields do not get populated because I think the constructor for my VF page controller is getting called a second time when redirecting to the 2nd page (I am not using setRedirect(true) so that should not happen). I have a feeling there is something different going on under the hood when using Force.com versus internal VF pages but I can't figure it out. Anyone familiar with Force.com pages and have any ideas? I posted some code in the posts below.

 

Best Answer chosen by Admin (Salesforce Developers) 
DaveHDaveH

Nevermind guys I found an old post that solved the issue. My custom object's status was "In Development" instead of "Deployed". Another example of lack of Documentation on SF's side. Glad we have good people watching the forums.

All Answers

DaveHDaveH

The controller:

 

public class PortalChangePreferencesController {

    public Subscription__c subscription { get; set; }
    private boolean redirect = true;
    
    public PortalChangePreferencesController() {
        String subId = ApexPages.CurrentPage().getParameters().get('subId');
        System.debug('SUB ID = ' + subId);
        
        if(subId != null && !subId.trim().equals(''))
        {
            Subscription__c result = [select Id, Email__c, Contact_First_Name__c, Contact_Last_Name__c,
                                        Product_Info__c, News_Events__c
                                        from Subscription__c 
                                        where Id = :subId limit 1];
            
            if(result == null)
            {
                redirect = false;
            }
            else
            {
                this.subscription = result; 
            }
        }
        else
        {
            redirect = false;
        }
    }
    
    public PageReference redirectToPrefsPage() {
        if(redirect)
        {
            return Page.PrefLoginPage;
        }
        else return Page.Unauthorized;
    }
    
    public PageReference save() {
        update subscription;
        return null;
    }
    
    public PageReference unsubscribe() {
        return null;
    }
}

 The VF page that redirects the user:

 

<apex:page controller="PortalChangePreferencesController" showHeader="false" sidebar="false" id="thisPage">
<apex:form >
  <h1>Redirecting....</h1>
  <apex:commandButton action="{!redirectToPrefsPage}" rendered="true" id="button1"/>
  
  <script>
      var button = document.getElementById("{!$Component.button1}");
  </script>
  
</apex:form>

    <script>
     
      window.onload = new function() { button.click(); }
  </script>
</apex:page>

 

DaveHDaveH

Nevermind guys I found an old post that solved the issue. My custom object's status was "In Development" instead of "Deployed". Another example of lack of Documentation on SF's side. Glad we have good people watching the forums.

This was selected as the best answer
lakslaks

Hi Dave,

 

We are facing a similar problem.


When the VF pages were moved to Site, the redirection that was working fine fails to work anymore.

The requirement is that we need to traverse across some 4,5 pages capturing the user entry in each and carrying it till the last page where we are doing a save to an object.


I have associated the same controller with all pages and redirecting using:

PageReference redirect = new PageReference('/apex/survey3');       
return redirect;

 

This works fine before moving to Sites.
But once moved to Sites, it doesn't redirect at all, just refreshes the same page.

 

When the code is changed as below, it redirects but the view state is not maintained I guess and hence the values are not carried over as required.

PageReference redirect = new PageReference('/survey3');
return redirect;

 

Could you provide any information on what might be wrong ?

Thanks in advance.

 

Regards,

Lakshmi.