您好我正在尝试将visualforce页面重定向到google.com页面 这是我的VF代码
<apex:page controller="google_redir">
<!-- Begin Default Content REMOVE THIS -->
<h1>Congratulations</h1>
This is your new Page
<!-- End Default Content REMOVE THIS -->
<apex:form >
<apex:commandButton action="{! hello1}" value="Save New Account Value"/>
</apex:form>
</apex:page>
这是我的顶级控制器代码
public class google_redir{
public PageReference hello1(){
PageReference reference=new PageReference('http://www.google.com');
reference.setRedirect(true);
return reference;
}
}
页面未重定向到google.com,显示空白页面。 请帮我纠正错误,我错了,为什么它没有重定向到google.com页面。
答案 0 :(得分:4)
尝试切换到标准的Visualforce页面时遇到了类似的问题。我直接从教程中获取了代码,就像Ritesh我得到了一个空白页面 以下是教程链接:http://www.salesforce.com/us/developer/docs/pages/index.htm 和代码:
public PageReference save() {
// Add the account to the database.
insert account;
// Send the user to the detail page for the new account.
PageReference acctPage = new ApexPages.StandardController(account).view();
acctPage.setRedirect(true);
return acctPage;
}
我通过观察FireBug(Firefox)中的结果找到了解决方案。该问题是由权限拒绝错误引起的。一旦我禁用了开发模式,页面重定向工作正常。
我希望问题及其解决方案的这种替代变体将在某一天帮助某人。
答案 1 :(得分:2)
您发布的确切代码对我有用。单击http://www.google.com
按钮后,我被重定向到Save New Account Value
。为了便于阅读,我在测试后稍微修改了你的代码:
网页强>
<apex:page controller="google_redir">
<apex:form >
<apex:commandButton action="{!hello1}" value="Save New Account Value"/>
</apex:form>
</apex:page>
<强>控制器强>
public class google_redir {
public PageReference hello1() {
PageReference reference=new PageReference('http://www.google.com');
reference.setRedirect(true);
return reference;
}
}
您的浏览器或Internet连接是否存在问题?尝试重定向到不同的网址,例如http://www.salesforce.com
或使用其他互联网浏览器,只是为了查看是否有效。
答案 2 :(得分:0)
听起来这已经得到了解答但只是想补充一点,在这种情况下你不需要将重定向设置为true。只有当你想保持视图状态时才会这样。如果您要离开Salesforce,则无法维护视图状态。
return new PageReference('http://yrt.ca/');
答案 3 :(得分:-1)
我们需要使用以下代码语法导航到外部网址 PageReference reference = new PageReference(&#39; External Url&#39;);。
中的示例