博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
salesforce 零基础学习(六十)Wizard样式创建数据
阅读量:4695 次
发布时间:2019-06-09

本文共 9335 字,大约阅读时间需要 31 分钟。

项目中表之间关联关系特别多,比如三个表中A,B,C  C作为主表,A,B作为从表,有时候C表需要创建数据时,同时需要创建A,B两个表的数据,这种情况下,使用Wizard样式会更加友好。

以Goods__c表和Goods_Vendor__c表为例,Goods__c为主表,Goods_Vendor__c为从表。新建Goods__c记录以后同时要创建其相关的数据。

表结构关系如下:

 

代码:

1.GoodsHelper:封装获取goods的列表方法

1 public without sharing class GoodsHelper { 2      3     public static final String BASE_GOODS_QUERY = 'SELECT CreatedById, CreatedDate, IsDeleted,' +  4                     ' Goods_Code_Unique__c, Name, GoodsPicture__c, GoodsBrand__c, GoodsCostPrice__c,' +  5                     ' GoodsDescribe__c, GoodsName__c, GoodsPrice__c, GoodsProfit__c, Is_Draft__c,' + 6                     ' LastModifiedById, LastModifiedDate, No__c, OwnerId, Id, RecordTypeId,' + 7                     ' Status__c, SystemModstamp' + 8                     ' FROM Goods__c where IsDeleted = false'; 9     public static final String BASE_GOODS_COUNT_QUERY = 'SELECT count() from Goods__c where IsDeleted = false';10     public static MyPaginationEnhancement getGoodsList(String goodsName,String goodsBrand,MyPaginationEnhancement pagination) {11         String queryCondition= '';12         String orderBy ='';13         if(goodsName != null) {14             queryCondition += ' and GoodsName__c like %\'' + goodsName + '%\'';15         }16         if(goodsBrand != null) {17             queryCondition += ' and GoodsBrand__c = :goodsBrand';18         }19         orderBy = ' order by createddate';20         21         pagination.getQueryResult(BASE_GOODS_COUNT_QUERY,BASE_GOODS_QUERY,queryCondition,null,orderBy);22         return pagination;23     }24 }

2.GoodsListController:Goods列表Controller

1 public with sharing class GoodsListController { 2     public Map
parameters; 3 4 public GoodsListController() { 5 parameters=ApexPages.currentPage().getParameters(); 6 init(); 7 } 8 9 public MyPaginationEnhancement pagination = new MyPaginationEnhancement();10 11 public String goodsName{get;set;}12 13 public String goodsBrand{get;set;}14 15 16 public void init() {17 queryByCondition();18 }19 20 public void queryByCondition() {21 GoodsHelper.getGoodsList(goodsName,goodsBrand,pagination);22 }23 24 public MyPaginationEnhancement resultPagination{25 get{26 if(pagination ==null){27 pagination =new MyPaginationEnhancement();28 }29 return pagination;30 }31 set;32 }33 34 public List
resultList{35 get{36 if(pagination==null || pagination.resultList==null){37 return new List
(); 38 }39 return pagination.resultList;40 }41 set;42 }43 44 public PageReference newGoods() {45 return Page.detailGoods;46 }47 48 public void firstPage() {49 pagination.first();50 queryByCondition(); 51 } 52 53 public void lastPage() {54 pagination.last();55 queryByCondition(); 56 } 57 58 public void previousPage() {59 pagination.previous();60 queryByCondition(); 61 } 62 63 public void nextPage() {64 pagination.next();65 queryByCondition();66 }67 }

3.GoodsListPage

1 
2
11 12
13
14
15
16
17
18
19
20
{!$ObjectType.Goods__c.fields.GoodsName__c.label}
21
22
23
24
{!$ObjectType.Goods__c.fields.GoodsPrice__c.label}
25
26
27
28
{!$ObjectType.Goods__c.fields.GoodsCostPrice__c.label}
29
30
31
32
操作
33
编辑34
35
36
37
38 39
41
43
45
47
48
49
52
56
57
58
61
65
66
67
69
70
71
74
78
79
80
83
87
88
89
90
91
92
93
94
95
96

4.GoodsDetailController:此类中封装了Wizard的相关方式,Wizard的相关跳转均为转发方式。

1 public with sharing class GoodsDetailController {  2       3     /*入口是新建还是更新:新建为false,更新为true*/  4     public Boolean isEditView{  5         get {  6             if(isEditView == null) {  7                 isEditView = false;  8             }  9             return isEditView; 10         } 11         set; 12     } 13      14     public GoodsDetailController() { 15         init(); 16     } 17      18     public GoodsDetailController(ApexPages.StandardController controller) { 19         init(); 20     } 21      22     public void init() { 23         String goodsId = ApexPages.currentPage().getParameters().get('goodsId'); 24         if(goodsId != null) { 25             isEditView = true; 26             String queryGoods = 'SELECT Goods_Code_Unique__c, Name, GoodsBrand__c,' + 27             ' GoodsCostPrice__c, GoodsDescribe__c, GoodsName__c, GoodsPrice__c,' + 28             ' GoodsProfit__c, No__c,Id, Status__c' + 29             ' FROM Goods__c where Id = :goodsId'; 30             String queryGoodsVendor = 'SELECT Goods__c, Id, Vendor_Name__c' + 31             ' FROM Goods_Vendor__c where Goods__c = :goodsId'; 32             List
goodsList = Database.query(queryGoods); 33 if(goodsList != null && goodsList.size() > 0) { 34 goods = goodsList.get(0); 35 } 36 List
goodsVendorList = Database.query(queryGoodsVendor); 37 if(goodsVendorList != null && goodsVendorList.size() > 0) { 38 goodsVendor = goodsVendorList.get(0); 39 } 40 } 41 } 42 43 public Goods__c goods{ 44 get{ 45 if(goods == null) { 46 goods = new Goods__c(); 47 } 48 return goods; 49 } 50 set; 51 } 52 53 public Goods_Vendor__c goodsVendor{ 54 get{ 55 if(goodsVendor == null) { 56 goodsVendor = new Goods_Vendor__c(); 57 } 58 return goodsVendor; 59 } 60 set; 61 } 62 63 public PageReference saveFinally() { 64 Savepoint sp = Database.setSavepoint(); 65 try { 66 upsert goods; 67 goodsVendor.Goods__c = goods.Id; 68 upsert goodsVendor; 69 } catch(DMLException e) { 70 Database.rollback(sp); 71 ApexPages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.ERROR,e.getMessage())); 72 return null; 73 } 74 return redirectToGoodsList(); 75 } 76 77 78 79 public PageReference redirectToGoods() { 80 return Page.detailGoods; 81 } 82 83 public PageReference redirectToVendor() { 84 return Page.detailVendor; 85 } 86 87 public PageReference redirectToTotal() { 88 return Page.detailGoodsTotal; 89 } 90 91 public PageReference cancelCreateGoods() { 92 if(!isEditView) { 93 if(goodsVendor != null && goodsVendor.Id != null) { 94 delete goodsVendor; 95 } 96 if(goods != null && goods.Id != null) { 97 delete goods; 98 } 99 }100 return redirectToGoodsList();101 }102 103 public PageReference redirectToGoodsList() {104 PageReference ref = new PageReference('/apex/GoodsListPage');105 ref.setRedirect(true);106 return ref;107 }108 109 }

5.detailGoods.page:商品信息详情页面

1 
2
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

6.detailVendor.page:vendor详情页

1 
2
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

7.detailTotal.page:用于显示goods以及vendor的详细信息以及提交按钮

1 
2
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

效果展示:

1.商品列表

2.点击编辑,如果点击新建其他内容均为空,此处只显示编辑

3.点击next进入vendor页面

4.total页面

5.点击save以后,成功则跳转到list页面,失败则显示失败ERROR

失败情况:

 

成功情况:

 

总结:Wizard适用于新建数据时创建一套级联数据情况,篇中step1-3之间的跳转均使用转发方式,而不是重定向(ref.setRedirect(true)),原因为:三个页面绑定了同一个controller,转发方式第一次进入走构造函数,以后均不在走构造函数,而重定向需要每次都走构造函数。如果使用重定向,则前一页修改的数据重定向以后在回此页面,修改的数据便会回滚到以前的状态。有错误的地方欢迎指正,有问题欢迎留言。



 

转载于:https://www.cnblogs.com/zero-zyq/p/6230281.html

你可能感兴趣的文章
20165214 2018-2019-2 《网络对抗技术》Exp5 MSF基础应用 Week8
查看>>
常用JS大全
查看>>
JAVA-多线程
查看>>
常用加密算法
查看>>
MYSQL培训准备(2):MYSQL自增长陷阱
查看>>
IDEA 创建普通的maven+java Project
查看>>
背包专题练习
查看>>
Python学习笔记(二)
查看>>
T-SQL: Create folders in remote server by sql statement
查看>>
linux SVN安装及配置教程
查看>>
poj1088 滑雪问题 dfs写法
查看>>
ZooKeeper 概述
查看>>
Django的认证系统
查看>>
GDC China 2011见闻与感悟
查看>>
[工作笔记]JDK版本不同导致的SSL异常
查看>>
java.sql.DataTruncation: Data truncation
查看>>
给dubbo接口添加白名单——dubbo Filter的使用
查看>>
linux怎样使用top命令查看系统状态
查看>>
C# DataTable.Select()方法,条件中使用类型转换
查看>>
java 装饰者类
查看>>