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、其他问题,请在评论区留下你的
阅读全文