So either I'm going nuts, or I'm overlooking something obvious, or I'm just encountering some very weird behaviour.
The Setup
I have a page which calls an Init
action in the controller from the page tag
<apex:page controller="myController" action="{!Init}">
The Init()
method returns a PageReference.
I'm using some of Michaelforce's code to detect whether or not I'm in a sandbox environment, and if so I return a page reference to redirect the user. If not, I just return null
so that the page loads as normal.
public PageReference Init()
{
if(WhereAmI.IsSandbox())
{
PageReference pr = Page.PackPrefix__OtherPage;
return pr.setRedirect(true);
}
return null;
}
The Problem
This code works in my development environment, i.e. it doesn't redirect. If i change my if statement for testing to if(!WhereAmI.IsSandbox())
then it correctly redirects also.
Once I package the code up and install the package (managed) in a sandbox, it does not redirect. I made the WhereAmI
class and its methods global
so that I could test them in Execute it's functioning perfectly, returning true
and yet I don't get redirected.
The page does have a different content type to normal but I don't think that's the issue given that it works in production. So the quesiton: have I missed something that's right under my nose, or does this smell like a bug?
new pageReference('/apex/THEPAGE');
instead ofPage.THEPAGE
?