【问题标题】:Trying to add output link on redirect page to newly created Opportunity from another VF page尝试将重定向页面上的输出链接添加到来自另一个 VF 页面的新创建的机会
【发布时间】:2021-04-30 15:19:56
【问题描述】:

SF 管理员尝试进入 Dev。尝试使用 Force.com 站点、Apex 和 VF 的组合创建一些网络机会功能。它有效并且创造了机会。当 Opp 保存在 VF 页面上时,它会重定向到另一个 VF 页面,上面写着 Congrats!创建了新的 Opp 等。我想在此重定向页面上添加一个链接或按钮,以便用户可以选择导航到新创建的 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>

恭喜我希望链接/按钮路由到 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>

任何建议,帮助表示赞赏。

【问题讨论】:

    标签: salesforce apex visualforce


    【解决方案1】:

    我不确定您为什么在创建机会后重定向到新页面。为什么不在当前页面上显示成功消息并添加指向新页面的链接

    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>
    

    【讨论】:

    • 感谢 Psymn 的反馈...不幸的是,输出链接将我放入主页选项卡而不是机会。看起来我需要一种方法来将页面创建的机会的 ID 存储在控制器中,并将其传回 VF 以在输出链接中使用。您知道如何实现这一目标吗?
    • 摆弄了控制器/VF 页面,终于让它工作了。我会发布修改后的代码。
    【解决方案2】:

    首先在你的控制器中修改 reRend.setRedirect(true) 为 reRend.setRedirect(false) 第二件事是,当您想在创建新机会后显示消息时, 为什么我们需要另一个控制器?... 在 Saveto() 方法中插入新的机会之后 添加
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,'New oppournity is created'));

    只需提及 apex:pagemessages/ 在视觉力页面中调用此消息 现在在 apex:outputlink 中提到新创建的机会

    【讨论】:

      【解决方案3】:

      感谢 Psymn 为我指明了正确的方向。由于记录 ID 为空(可能是因为我没有使用标准控制器 - Dev n00b sorry),输出链接让我进入了主页选项卡。创建了一个字符串变量来获取 ID 的值,并在输出链接中引用了这个变量。

      控制器:

      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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-06-19
        • 2012-01-27
        • 1970-01-01
        • 2019-04-17
        • 2017-11-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多