用Visualforce Page创建向导页面

一、需求阐述

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

二、代码实现
Page 01
page01

    
    
    
        
            
                
                
            
            
                
                
                
            
            
                
                
            
        
    

Page 02
page02

    
    
    
        
            
                
                
                
                
                
            
            
            
            
        
    

Page 03
page03

    
    
    
        
            
                
                
            
            
                
                
                
                
            
            
                
                
                
            
            
            
            
        
    

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创建向导页面)