尝试将重定向页面上的输出 link 添加到来自另一个 VF 页面的新创建机会
Trying to add output link on redirect page to newly created Opportunity from another VF page
SF Admin 正在尝试进入 Dev。尝试使用 Force.com 站点、Apex 和 VF 的组合创建一些网络机会功能。它奏效并创造了机会。当 Opp 保存在 VF 页面上时,它会重定向到另一个 VF 页面,说恭喜!创建了新的 Opp 等。我想在此重定向页面上添加一个 link 或按钮,以便用户可以选择导航到新创建的 Opp(如果他们愿意),但是我运气不佳。
控制器:
public class OpportunityInformationPage{
public opportunity oppString{get;set;}
public OpportunityInformationPage(){
oppString = new opportunity();
}
public PageReference Saveto(){
opportunity opp = new opportunity();
opp.name = oppString.name;
opp.closedate = oppString.closedate;
opp.stagename = oppString.stagename;
opp.amount = oppString.amount;
opp.impact_level__c = oppString.impact_level__c;
insert opp;
PageReference reRend = new PageReference('/apex/Opportunity_Created');
reRend.setRedirect(true);
return reRend;
}
}
用于输入 Opp 详细信息的 VF 页面:
<apex:page controller="OpportunityInformationPage" showHeader="false" sidebar="false">
<apex:sectionHeader title="New Opportunity"/>
<apex:form >
<apex:pageBlock title="Opportunity Edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Saveto}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Opportunity Information">
<apex:inputField value="{!oppString.name}"/>
<apex:inputField value="{!oppString.closeDate}"/>
<apex:inputField value="{!oppString.stageName}"/>
<apex:inputField value="{!oppString.amount}"/>
<apex:inputField value="{!oppString.Impact_Level__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
恭喜页面,我希望 link/button 路由到 SF:
<apex:page controller="OpportunityInformationPage" showheader="false" sidebar="false">
<apex:PageBlock >
<apex:pageBlockSection >
<apex:outputText value="Congratulations! New Opportunity Succesfully Created" /> <br/>
</apex:pageBlockSection>
</apex:PageBlock>
</apex:page>
任何建议,帮助表示赞赏。
我不确定您为什么在创建机会后重定向到新页面。为什么不直接在当前页面上显示成功消息并在新的
中添加 link
public class OpportunityInformationPage{
public opportunity oppString{get;set;}
public Boolean bOppCreated{get;set;}
public OpportunityInformationPage(){
oppString = new opportunity();
bOppCreated = false;
}
public PageReference Saveto(){
opportunity opp = new opportunity();
opp.name = oppString.name;
opp.closedate = oppString.closedate;
opp.stagename = oppString.stagename;
opp.amount = oppString.amount;
opp.impact_level__c = oppString.impact_level__c;
insert opp;
bOppCreated = true;
return null;
}
}
<apex:page controller="OpportunityInformationPage" showHeader="false" sidebar="false">
<apex:sectionHeader title="New Opportunity"/>
<apex:form >
<apex:pageBlock title="Opportunity Edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Saveto}" rerender="mainBlock" />
</apex:pageBlockButtons>
<apex:outputpanel id="mainBlock">
<apex:pageBlockSection title="Opportunity Information" rendered="{!NOT(bOppCreated)>
<apex:inputField value="{!oppString.name}"/>
<apex:inputField value="{!oppString.closeDate}"/>
<apex:inputField value="{!oppString.stageName}"/>
<apex:inputField value="{!oppString.amount}"/>
<apex:inputField value="{!oppString.Impact_Level__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection rendered="{!bOppCreated}">
<apex:outputText value="Congratulations! New Opportunity Succesfully Created" /> <br/>
<apex:outputlink value="/{!oppString.id}">{!oppString.Name}</apex:outputlink>
</apex:pageBlockSection>
</apex:outputpanel>
</apex:pageBlock>
</apex:form>
</apex:page>
首先在控制器中将reRend.setRedirect(true)修改为reRend.setRedirect(false)
第二件事是当你想在创造新机会后显示消息时,
为什么我们需要另一个控制器?..
在 Saveto() 方法中插入新的机会之后
添加
ApexPages.addmessage(新ApexPages.message(ApexPages.severity.INFO,'New oppournity is created'));
通过简单提及apex:pagemessages/在视觉力页面中调用此消息
现在在 apex:outputlink 中提及新创造的机会
感谢 Psymn 为我指明了正确的方向。由于记录 ID 为空,输出 link 使我进入主页选项卡(认为这可能是因为我没有使用标准控制器 - Dev n00b 抱歉)。创建了一个字符串变量来获取 ID 的值,并在输出中引用了它 link,这起到了作用。
控制器:
public class OpportunityInformationPage{
public opportunity oppString{get;set;}
public Boolean bOppCreated{get;set;}
public String opp_sfid{get;set;}
public OpportunityInformationPage(){
oppString = new opportunity();
bOppCreated = false;
opp_sfid = null;
}
public PageReference Saveto(){
opportunity opp = new opportunity();
opp.name = oppString.name;
opp.closedate = oppString.closedate;
opp.stagename = oppString.stagename;
opp.amount = oppString.amount;
opp.impact_level__c = oppString.impact_level__c;
insert opp;
bOppCreated = true;
opp_sfid = opp.id;
return null;
}
}
VF 页面:
<apex:page controller="OpportunityInformationPage" showHeader="false" sidebar="false">
<apex:sectionHeader title="New Opportunity"/>
<apex:form >
<apex:pageBlock title="Opportunity Edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Saveto}" rerender="mainBlock"/>
</apex:pageBlockButtons>
<apex:outputPanel id="mainBlock">
<apex:pageBlockSection title="Opportunity Information" rendered="{!NOT(bOppCreated)}">
<apex:inputField value="{!oppString.name}"/>
<apex:inputField value="{!oppString.closeDate}"/>
<apex:inputField value="{!oppString.stageName}"/>
<apex:inputField value="{!oppString.amount}"/>
<apex:inputField value="{!oppString.Impact_Level__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection rendered="{!bOppCreated}">
<apex:outputText value="Congratulations! New Opportunity Succesfully Created" /> <br/>
<apex:outputlink value="/{!opp_sfid}">{!oppString.Name}</apex:outputlink>
</apex:pageBlockSection>
</apex:outputpanel>
</apex:pageBlock>
</apex:form>
</apex:page>
SF Admin 正在尝试进入 Dev。尝试使用 Force.com 站点、Apex 和 VF 的组合创建一些网络机会功能。它奏效并创造了机会。当 Opp 保存在 VF 页面上时,它会重定向到另一个 VF 页面,说恭喜!创建了新的 Opp 等。我想在此重定向页面上添加一个 link 或按钮,以便用户可以选择导航到新创建的 Opp(如果他们愿意),但是我运气不佳。
控制器:
public class OpportunityInformationPage{
public opportunity oppString{get;set;}
public OpportunityInformationPage(){
oppString = new opportunity();
}
public PageReference Saveto(){
opportunity opp = new opportunity();
opp.name = oppString.name;
opp.closedate = oppString.closedate;
opp.stagename = oppString.stagename;
opp.amount = oppString.amount;
opp.impact_level__c = oppString.impact_level__c;
insert opp;
PageReference reRend = new PageReference('/apex/Opportunity_Created');
reRend.setRedirect(true);
return reRend;
}
}
用于输入 Opp 详细信息的 VF 页面:
<apex:page controller="OpportunityInformationPage" showHeader="false" sidebar="false">
<apex:sectionHeader title="New Opportunity"/>
<apex:form >
<apex:pageBlock title="Opportunity Edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Saveto}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Opportunity Information">
<apex:inputField value="{!oppString.name}"/>
<apex:inputField value="{!oppString.closeDate}"/>
<apex:inputField value="{!oppString.stageName}"/>
<apex:inputField value="{!oppString.amount}"/>
<apex:inputField value="{!oppString.Impact_Level__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
恭喜页面,我希望 link/button 路由到 SF:
<apex:page controller="OpportunityInformationPage" showheader="false" sidebar="false">
<apex:PageBlock >
<apex:pageBlockSection >
<apex:outputText value="Congratulations! New Opportunity Succesfully Created" /> <br/>
</apex:pageBlockSection>
</apex:PageBlock>
</apex:page>
任何建议,帮助表示赞赏。
我不确定您为什么在创建机会后重定向到新页面。为什么不直接在当前页面上显示成功消息并在新的
中添加 linkpublic class OpportunityInformationPage{
public opportunity oppString{get;set;}
public Boolean bOppCreated{get;set;}
public OpportunityInformationPage(){
oppString = new opportunity();
bOppCreated = false;
}
public PageReference Saveto(){
opportunity opp = new opportunity();
opp.name = oppString.name;
opp.closedate = oppString.closedate;
opp.stagename = oppString.stagename;
opp.amount = oppString.amount;
opp.impact_level__c = oppString.impact_level__c;
insert opp;
bOppCreated = true;
return null;
}
}
<apex:page controller="OpportunityInformationPage" showHeader="false" sidebar="false">
<apex:sectionHeader title="New Opportunity"/>
<apex:form >
<apex:pageBlock title="Opportunity Edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Saveto}" rerender="mainBlock" />
</apex:pageBlockButtons>
<apex:outputpanel id="mainBlock">
<apex:pageBlockSection title="Opportunity Information" rendered="{!NOT(bOppCreated)>
<apex:inputField value="{!oppString.name}"/>
<apex:inputField value="{!oppString.closeDate}"/>
<apex:inputField value="{!oppString.stageName}"/>
<apex:inputField value="{!oppString.amount}"/>
<apex:inputField value="{!oppString.Impact_Level__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection rendered="{!bOppCreated}">
<apex:outputText value="Congratulations! New Opportunity Succesfully Created" /> <br/>
<apex:outputlink value="/{!oppString.id}">{!oppString.Name}</apex:outputlink>
</apex:pageBlockSection>
</apex:outputpanel>
</apex:pageBlock>
</apex:form>
</apex:page>
首先在控制器中将reRend.setRedirect(true)修改为reRend.setRedirect(false)
第二件事是当你想在创造新机会后显示消息时,
为什么我们需要另一个控制器?..
在 Saveto() 方法中插入新的机会之后
添加
ApexPages.addmessage(新ApexPages.message(ApexPages.severity.INFO,'New oppournity is created'));
通过简单提及apex:pagemessages/在视觉力页面中调用此消息 现在在 apex:outputlink 中提及新创造的机会
感谢 Psymn 为我指明了正确的方向。由于记录 ID 为空,输出 link 使我进入主页选项卡(认为这可能是因为我没有使用标准控制器 - Dev n00b 抱歉)。创建了一个字符串变量来获取 ID 的值,并在输出中引用了它 link,这起到了作用。
控制器:
public class OpportunityInformationPage{
public opportunity oppString{get;set;}
public Boolean bOppCreated{get;set;}
public String opp_sfid{get;set;}
public OpportunityInformationPage(){
oppString = new opportunity();
bOppCreated = false;
opp_sfid = null;
}
public PageReference Saveto(){
opportunity opp = new opportunity();
opp.name = oppString.name;
opp.closedate = oppString.closedate;
opp.stagename = oppString.stagename;
opp.amount = oppString.amount;
opp.impact_level__c = oppString.impact_level__c;
insert opp;
bOppCreated = true;
opp_sfid = opp.id;
return null;
}
}
VF 页面:
<apex:page controller="OpportunityInformationPage" showHeader="false" sidebar="false">
<apex:sectionHeader title="New Opportunity"/>
<apex:form >
<apex:pageBlock title="Opportunity Edit" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Saveto}" rerender="mainBlock"/>
</apex:pageBlockButtons>
<apex:outputPanel id="mainBlock">
<apex:pageBlockSection title="Opportunity Information" rendered="{!NOT(bOppCreated)}">
<apex:inputField value="{!oppString.name}"/>
<apex:inputField value="{!oppString.closeDate}"/>
<apex:inputField value="{!oppString.stageName}"/>
<apex:inputField value="{!oppString.amount}"/>
<apex:inputField value="{!oppString.Impact_Level__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection rendered="{!bOppCreated}">
<apex:outputText value="Congratulations! New Opportunity Succesfully Created" /> <br/>
<apex:outputlink value="/{!opp_sfid}">{!oppString.Name}</apex:outputlink>
</apex:pageBlockSection>
</apex:outputpanel>
</apex:pageBlock>
</apex:form>
</apex:page>