1

Consider that there is an org (using Salesforce Classic) where I've configured a Home Page Custom Component of type Visualforce Area – in which there is a visualforce page that does nothing but automatically redirects users to another visualforce page (let's say, a front page with custom style & useful links). I've added that custom component to the Home Page Layout and assigned it to the users.

Per my understanding, the classic redirect in force.com can be implemented with a combination of a visualforce page and controller:

public with sharing class redirect_controller {

    public PageReference redirect() {
        PageReference pageref = Page.customFrontPage;
        pageref.setRedirect(True);
        return pageref;
    }
}

<apex:page applyHtmlTag="false" 
           applyBodyTag="false" 
           showHeader="false" 
           showChat="false"
           sidebar="false"
           standardStylesheets="false"
           controller="redirect_controller"
           action="{!redirect}" >

</apex:page>

But the given code doesn't do the job I need. It only updates the contents of the Custom Home Page Component – I would hope that it would redirect user from the Home Page entirely, but no, oh well.

As dirty hack, the following code works, but it is against the best practices, and it is not a viable option, since the redirect gets blocked in Chrome Canary:

<apex:page applyHtmlTag="false" 
           applyBodyTag="false" 
           showHeader="false" 
           showChat="false"
           sidebar="false"
           standardStylesheets="false">

    <script type="text/javascript">
        top.location.href = '/apex/customFrontPage';
    </script>

</apex:page>

Still trying to figure out the proper way to redirect users from Home Page to another visualforce page without violating the same-origin policy.

1

You're right that you should not be using this behavior. Normally, you should set a Default Tab for the App that the user uses. When they log in, they will be redirected to this Tab automatically, if they are not configured to land on Setup by default. If you must redirect, you'll have to use the JavaScript method for Classic, because the "action" method can't affect the parent tab. As an aside, there's no need to actually use a controller for pages which redirect, as you can simply do this:

<apex:page action="{!URLFOR($Page.customFrontPage)}"></apex:page>

You might use this for a deprecated page when you want to automatically redirect to a different page, or conditionally (e.g. using IF statements).

  • Thank you for your input. I guess, I'll have to figure out now how I can emulate a user click in javascript to automatically 'click' the visualforce tab on the Home Page load. – wintermute Jan 14 '18 at 22:32
  • @wintermute That won't work; Visualforce has been specifically forced in to a position where it cannot affect the Salesforce UI when placed in an iframe (because they're from different domains). This was an intentional design intention. The method you have right now is as good as it gets. – sfdcfox Jan 14 '18 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.