salesforce 零基础学习(五十)自定义View或者List以及查看系统原来的View或者List

salesforce给我们提供了标准的页面,比如标准的页面包括标准的列表和标准的详细页视图。有的时候我们想要自定义视图,比如做一个项目的时候不希望使用者直接通过ID查看到标准的详细页,而是跳转到指定处理过的详细页,这个时候做法如下:

1.创建相关详细页的Controller,此Controller的构造函数应涵盖ApexPages.StandardController,ApexPages.StandardSetController两个参数

 

 1 public without sharing class CompanyDetailController {
 2     private Map<String,String> params;
 3     
 4     public Company_Info__c companyInfo{get;set;}
 5     
 6     public CompanyDetailController(ApexPages.StandardController controller) {
 7         init();
 8     }
 9     
10     public CompanyDetailController(ApexPages.StandardSetController controller) {
11         init();
12     }
13     
14     public void init() {
15         params = ApexPages.currentPage().getParameters();
16         String companyInfoId = params.get('id');
17         String fetchCompanyInfo = 'SELECT Company_Code_Unique__c, Company_Name__c, Company_Phone__c, Company_Place__c, Company_Type__c, CreatedDate,Employees_Number__c, Id FROM Company_Info__c where Id = :companyInfoId';
18         List<Company_Info__c> companyInfoList = Database.query(fetchCompanyInfo);
19         if(companyInfoList == null || companyInfoList.size() == 0) {
20             companyInfo = null;
21         } else {
22             companyInfo = companyInfoList.get(0);
23         }
24     }
25 }
CompanyDetailController

2.创建相应的page,此page用于显示view的布局

 1 <apex:page standardController="Company_Info__c" extensions="CompanyDetailController">
 2     <apex:pageBlock >  
 3         <apex:panelGrid columns="2" style="width:100%;" rendered="{!companyInfo == null}">
 4             不存在此ID对应的记录,请重新检查相关ID
 5         </apex:panelGrid>
 6         <apex:panelGrid columns="2" style="width:100%;" rendered="{!companyInfo != null}">
 7             <apex:outputLabel value="{!$ObjectType.Company_Info__c.Fields.Company_Code_Unique__c.Label}" style="color: #830051;line-height: 24px;"/>
 8             <apex:outputLabel value="{!companyInfo.Company_Code_Unique__c}"/>
 9                 
10             <apex:outputLabel value="{!$ObjectType.Company_Info__c.Fields.Company_Name__c.Label}" style="color: #830051;line-height: 24px;"/>
11             <apex:outputLabel value="{!companyInfo.Company_Name__c}"/>
12             
13             <apex:outputLabel value="{!$ObjectType.Company_Info__c.Fields.Company_Phone__c.Label}" style="color: #830051;line-height: 24px;"/>
14             <apex:outputLabel value="{!companyInfo.Company_Phone__c}"/>
15              
16             <apex:outputLabel value="{!$ObjectType.Company_Info__c.Fields.Company_Place__c.Label}" style="color: #830051;line-height: 24px;"/>
17             <apex:outputLabel value="{!companyInfo.Company_Place__c}"/>
18                                   
19             <apex:outputLabel value="{!$ObjectType.Company_Info__c.Fields.Company_Type__c.Label}" style="color: #830051;line-height: 24px;"/>
20             <apex:outputLabel value="{!companyInfo.Company_Type__c}"/>               
21               
22             <apex:outputLabel value="{!$ObjectType.Company_Info__c.Fields.Employees_Number__c.Label}" style="color: #830051;line-height: 24px;"/>
23             <apex:outputLabel value="{!companyInfo.Employees_Number__c}"/>
24         </apex:panelGrid> 
25     </apex:pageBlock> 
26 </apex:page>
CompanyDetailPage

3.修改Company Info这个object的view,修改成override with visualforce Page

 4.显示效果:当在窗口输入:https://c.ap2.visual.force.com/a032800000JG8c0AAD访问以后会自动跳转到

https://c.ap2.visual.force.com/apex/CompanyDetailPage?id=a032800000JG8c0AAD&sfdc.override=1

通过以上几步可以实现自定义view的操作。那么问题来了,如果我是admin,我想通过这条记录ID,查看他的原始信息,查看他的审批流程,但是这条记录的view视图已经被override了怎么办,可以采用此种操作进行查看原始的记录view视图。

https://ap2.salesforce.com/a032800000JG8c0AAD?nooverride=1    此种访问便可以显示原来的view视图

 

总结:此篇主要想强调的是view视图被override以后想要看原始的视图方式,相信很多人都会,在此写成一篇博客,方便自己以后忘记时查看,此篇如果有错误的地方欢迎指正,有不懂的地方欢迎留言。

posted @ 2016-11-10 09:29  zero.zhang  阅读(2669)  评论(1编辑  收藏  举报