Salesfroce重写记录类型选择页面

来源:互联网 发布:linux查看用户所属组 编辑:程序博客网 时间:2024/06/03 21:40

场景描述:在做订单管理的时候,订单的记录类型有很多,不同的用户对不同的记录类型的维护权限大不一样,比如有5个订单记录类型,其中只有促销订单的记录类型不允许用户从Order Tab处创建,这时如果沿用标准的记录类型选择页面,用户体验终究不好。所以需要重写订单记录类型选择页面来过滤掉促销订单这种特殊情况,以下是解决方案。

Apex Code:

public class ACC_OrderRecordTypeSelection {public List<String> rtIds {get;set;}public List<RecordType> rtList {get;set;}    public List<SelectOption> listViewOptions {get;set;}public String filterId {get;set;}public ACC_OrderRecordTypeSelection(ApexPages.StandardController controller) {rtIds = new List<String>();rtList = new List<RecordType>();listViewOptions = new List<SelectOption>();List<RecordTypeInfo> rtInfoList = Schema.Order.SObjectType.getDescribe().getRecordTypeInfos();System.debug('rtInfoList: ' + rtInfoList);// Judge whether the order record type is customizedif(rtInfoList.size() > 0 && rtInfoList.size() == 1 && rtInfoList[0].getName().equals(Label.ACC_Order_Master_RT_Label_Name)) {        listViewOptions.add(new SelectOption(rtInfoList[0].getRecordTypeId(), rtInfoList[0].getName()));        rtIds.add(rtInfoList[0].getRecordTypeId());        }else {        for(RecordTypeInfo info: rtInfoList) {    System.debug('info: ' + info);    if(info.isAvailable()) {     //filter recordtype which is not equal to promotion order    if(info.getName().equals(Label.ACC_Promotion_Order_RecordType_Label_Name) || info.getName().equals(Label.ACC_Order_Master_RT_Label_Name)) {    continue;    }else {    listViewOptions.add(new SelectOption(info.getRecordTypeId(), info.getName()));    rtIds.add(info.getRecordTypeId());    }    }        }        if(rtIds.size() > 0) {        rtList = [SELECT Name, Description FROM RecordType WHERE Id IN :rtIds];        }}}public PageReference ACC_CreateOrder() {    System.debug('filterId: ' + filterId);    //return new PageReference('/801/e?retURL=%2F801%2Fo&RecordType='+ filterId +'&ent=Order');    //return new PageReference('/801/e?&RecordType='+ filterId);    PageReference newPage = new PageReference('/801/e?&RecordType='+ filterId +'+&retURL=/apex/ACC_OrderRecordTypeSelection&ent=Order&nooverride=1');    return newPage;    }}
Visualforce Code:

<apex:page standardController="Order" extensions="ACC_OrderRecordTypeSelection" sidebar="false"><style>.noteMsg {margin-bottom: 16px;font-size: 109%;}.tableHeader {background: #f2f3f3;}</style><apex:sectionHeader title="{! $Label.ACC_New_Order_Label}" subtitle="{! $Label.ACC_Select_Order_Record_Type_Label}" help="https://help.salesforce.com/articleView?id=permissions_record_type_access.htm"/><apex:outputPanel layout="block" styleClass="noteMsg">{! $Label.ACC_Order_RecordType_Tip_Msg_Label}</apex:outputPanel><apex:form><apex:pageBlock title="{! $Label.ACC_Order_RecordType_Table_Title_Label}"><apex:pageBlockButtons location="bottom"><apex:commandButton value="{! $Label.ACC_Continue_Label}" action="{!ACC_CreateOrder}"/><!-- call standard cancel action --><apex:commandButton value="{! $Label.ACC_Cancel_Label}" action="{!cancel}"/></apex:pageBlockButtons><apex:pageBlockSection><apex:selectList value="{! filterId}" size="1">  <apex:outputLabel style="margin-right: 16px;"><h3>{! $Label.ACC_RecordType_Of_New_Record_Label}</h3></apex:outputLabel>                <apex:selectOptions value="{! listViewOptions}"/>              </apex:selectList> </apex:pageBlockSection></apex:pageBlock><h3 style="margin: 20px 0 10px;display: block;">{! $Label.ACC_Available_Label}</h3><apex:dataTable value="{!rtList}" var="rt" headerClass="tableHeader" border="1" cellpadding="4" cellspacing="0" style="border-color: #fff;">        <apex:column headerValue="{! $Label.ACC_Record_Type_Name_Label}"><h3>{!rt.Name}</h3></apex:column>        <apex:column headerValue="{! $Label.ACC_Description_Label}">{!rt.Description}</apex:column>    </apex:dataTable></apex:form></apex:page>

效果对比预览:



问题及解决方案:

1、如果需要做国际化,那么页面上的文字描述需要翻译,推荐使用Custom Label;

2、你可能会遇到点击continue按钮,重写的按钮跳转不过去,请处理url,参照代码加参数;

3、重写后需要将每个简档都分配apex/vf权限,否则会显示无权限;

4、其他问题,请在评论区留下你的

阅读全文
'); })();
1 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 和男神谈恋爱 廿朔 和男神谈恋爱廿朔txt书包下载 仙道 虫廿四 廿四节气顺序 廿四式太极拳 廿四味凉茶 廿四味凉茶的功效 二十四味凉茶功效 廿怎么读音是什么意思 廿读音 开家肉夹馍店 开家星巴克要多少钱 开海底捞要多少钱 开家服装店要多少钱 开一家汉堡店要多少钱 开一家花店一年大概能挣多少 开一家星巴克需要投资多少 2017县城开一家海底捞多少钱 开一家菜鸟驿站月收入 上海三枪内衣招聘信息 开业祝福词 开业主持词 开业祝贺词 开业主持词开场白 庆祝开业的祝贺词 公司开业祝酒词 商场开业典礼主持词 饭店开业词 开个无纺布袋厂 开个钢化玻璃厂要多少钱 开个修理厂大概多少钱 开个汽车修理厂多少钱 开一个汽修厂需要多少钱 丽贝乐纸尿裤好吗 丽贝乐婴儿纸尿裤 丽贝乐纸尿裤怎么样 盗贼厄运开书教程 厄运开书 穿书自救指南什么时候开更 小红书为什么打不开 开超市计划书