美文网首页
用Visualforce Page创建向导页面

用Visualforce Page创建向导页面

作者: 江江酱酱233 | 来源:发表于2019-10-29 18:27 被阅读0次
一、需求阐述

创建一个向导页面,分三步新建opportunity以及相应的account和contact并保存到系统中。

二、代码实现
Page 01
page01
<apex:page Controller="newOpportunityController " tabStyle="Opportunity">
    <script>
        function confirmCancel(){
            var isCancel = confirm("Are you sure to cancel?");
            if (isCancel) {return true;}
            return false;
        }
    </script>
    <apex:sectionHeader title="New Customer Opportunity" subtitle="Step 1 of 3"/>
    <apex:form>
        <apex:pageBlock title="Customer Information" mode = "edit">
            <apex:pageBlockSection title="Account Information">
                <apex:inputField id = "accountName" value="{!account.name}"/>
                <apex:inputField id = "accountSite" value="{!account.site}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Contact Information">
                <apex:inputField id = "contactFirstName" value="{!contact.firstname}"/>
                <apex:inputField id = "contactLastName" value="{!contact.lastname}"/>
                <apex:inputField id = "contactPhone" value="{!contact.phone}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons>
                <apex:commandButton value="Next" action="{!step2}"/>
                <apex:commandButton value="Cancel" action="{!cancel}" onclick="return confirmCancel()" immediate="true"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Page 02
page02
<apex:page controller="newOpportunityController" tabStyle="Opportunity">
    <script>
        function confirmCancel(){
            var isCancel = confirm("Are you sure to cancel?");
            if (isCancel) {return true;}
            return false;
        }
    </script>
    <apex:sectionHeader title="New Customer Opportunity" subtitle="Step 2 of 3"/>
    <apex:form>
        <apex:pageBlock title="Opportunity Information" mode = "edit">
            <apex:pageBlockSection title="Opportunity Information">
                <apex:inputField id="opportunityName" value="{!opportunity.Name}"/>
                <apex:inputField id="opportunityAmount" value="{!opportunity.Amount}"/>
                <apex:inputField id="opportunityClosedate" value="{!opportunity.closeDate}"/>
                <apex:inputField id="opportunityStagename" value="{!opportunity.StageName}"/>
                <apex:inputField id="contactRole" value="{!role.Role}"/>
            </apex:pageBlockSection>
            <apex:commandButton value="Previous" action="{!step1}"/>
            <apex:commandButton value="Next" action="{!step3}"/>
            <apex:commandButton value="Cancel" action="{!cancel}" onclick="return confirmCancel()" immediate = "true"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Page 03
page03
<apex:page controller="newOpportunityController" tabStyle="Opportunity">
    <script>
        function confirmCancel(){
            var isCancel = confirm("Are you sure to cancel?");
            if (isCancel) {return true;}
            return false;
        }
    </script>
    <apex:sectionHeader title="New Customer Opportunity" subtitle="Step 3 of 3"/>
    <apex:form>
        <apex:pageBlock title="Confirmation" mode = "edit">
            <apex:pageBlockSection title="Account Information">
                <apex:outputField value="{!account.Name}"/>
                <apex:outputField value="{!account.Site}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Contact Information">
                <apex:outputField value="{!contact.FirstName}"/>
                <apex:outputField value="{!contact.LastName}"/>
                <apex:outputField value="{!contact.Phone}"/>
                <apex:outputField value="{!role.Role}"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Opportunity Information">
                <apex:outputField value="{!opportunity.Name}"/>
                <apex:outputField value="{!opportunity.Amount}"/>
                <apex:outputField value="{!opportunity.CloseDate}"/>
            </apex:pageBlockSection>
            <apex:commandButton value="Previous" action="{!step2}"/>
            <apex:commandButton value="Save" action="{!save}"/>
            <apex:commandButton value="Cancel" action="{!cancel}" onclick="return confirmCancel()" immediate = "true"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Controller
public with sharing class newOpportunityController {
    Account account;
    Contact contact;
    Opportunity opportunity;
    OpportunityContactRole role;

    public Account getAccount(){
        if (account == null) account = new Account();
        return account;
    }

    public Contact getContact(){
        if (contact == null) contact = new Contact();
        return contact;
    }

    public Opportunity getOpportunity(){
        if (opportunity == null) opportunity = new Opportunity();
        return opportunity;
    }

    public OpportunityContactRole  getRole(){
        if (role == null) {
            role = new OpportunityContactRole();
        }
        return role;
    }

    public PageReference step1(){
        return Page.opptyStep1;
    }

    public PageReference step2(){
        return Page.opptyStep2;
    }

    public PageReference step3(){
        return Page.opptyStep3;
    }

    public PageReference cancel(){
        PageReference opportunityPage = new ApexPages.StandardController(opportunity).view();
        opportunityPage.setRedirect(true);
        return opportunityPage;
    }   

    public PageReference save(){
        account.Phone = contact.Phone;
        insert account;

        contact.accountId = account.Id;
        insert contact;

        opportunity.accountId = account.Id;
        insert opportunity;

        role.opportunityId = opportunity.Id;
        role.contactId = contact.Id;
        insert role;

        PageReference opptPage = new ApexPages.StandardController(opportunity).view();
        opptPage.setRedirect(true);
        return opptPage;
    }
}

参考:https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_wizard.htm

相关文章

  • 用Visualforce Page创建向导页面

    一、需求阐述 创建一个向导页面,分三步新建opportunity以及相应的account和contact并保存到系...

  • visualforce page

    public class ContactListController { private String sor...

  • Visualforce控制器

    Visualforce框架是遵循MVC结构的。Visualforce页面代表了“视图”部分,Salesforce的...

  • *2.RN页面跳转19-11-06

    1.创建页面 具体代码:HomePage.js Page1 Page2 Page3 2.创建navigators ...

  • ionic2基础

    创建page页面方法:ionic g page 页面名字 设定全局颜色,color颜色方法image.png 添加...

  • Axure

    引用页面:右击图块 > referance page(引用页面)> 选择页面 创建返回主页按钮:选择按钮 > pr...

  • 2.目录规划和home页面

    src目录 home页面 page目录下创建Home.vue

  • Flutter 常用Live Templates分享

    GetX相关 1.快速创建GetX页面(包含Page | Controller | Binding)

  • FineuiPro 加载动态列Grid

    前言 由于grid控件动态创建列只能在page_init事件里,不能直接用ajax方式,所以页面不刷新的话效果是出...

  • 聊天页SearchBar

    自定义SearchPage 新建search_page.dart文件,创建顶部搜索栏以及布局搜索页面 聊天页面搜索...

网友评论

      本文标题:用Visualforce Page创建向导页面

      本文链接:https://www.haomeiwen.com/subject/bwvgvctx.html