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以后想要看原始的視圖方式,相信很多人都會,在此寫成一篇博客,方便自己以后忘記時查看,此篇如果有錯誤的地方歡迎指正,有不懂的地方歡迎留言。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM