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

时间:2023-03-09 22:54:46
salesforce 零基础学习(五十)自定义View或者List以及查看系统原来的View或者List

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

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

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

 public without sharing class CompanyDetailController {
private Map<String,String> params; public Company_Info__c companyInfo{get;set;} public CompanyDetailController(ApexPages.StandardController controller) {
init();
} public CompanyDetailController(ApexPages.StandardSetController controller) {
init();
} public void init() {
params = ApexPages.currentPage().getParameters();
String companyInfoId = params.get('id');
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';
List<Company_Info__c> companyInfoList = Database.query(fetchCompanyInfo);
if(companyInfoList == null || companyInfoList.size() == 0) {
companyInfo = null;
} else {
companyInfo = companyInfoList.get(0);
}
}
}

CompanyDetailController

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

 <apex:page standardController="Company_Info__c" extensions="CompanyDetailController">
<apex:pageBlock >
<apex:panelGrid columns="2" style="width:100%;" rendered="{!companyInfo == null}">
不存在此ID对应的记录,请重新检查相关ID
</apex:panelGrid>
<apex:panelGrid columns="2" style="width:100%;" rendered="{!companyInfo != null}">
<apex:outputLabel value="{!$ObjectType.Company_Info__c.Fields.Company_Code_Unique__c.Label}" style="color: #830051;line-height: 24px;"/>
<apex:outputLabel value="{!companyInfo.Company_Code_Unique__c}"/> <apex:outputLabel value="{!$ObjectType.Company_Info__c.Fields.Company_Name__c.Label}" style="color: #830051;line-height: 24px;"/>
<apex:outputLabel value="{!companyInfo.Company_Name__c}"/> <apex:outputLabel value="{!$ObjectType.Company_Info__c.Fields.Company_Phone__c.Label}" style="color: #830051;line-height: 24px;"/>
<apex:outputLabel value="{!companyInfo.Company_Phone__c}"/> <apex:outputLabel value="{!$ObjectType.Company_Info__c.Fields.Company_Place__c.Label}" style="color: #830051;line-height: 24px;"/>
<apex:outputLabel value="{!companyInfo.Company_Place__c}"/> <apex:outputLabel value="{!$ObjectType.Company_Info__c.Fields.Company_Type__c.Label}" style="color: #830051;line-height: 24px;"/>
<apex:outputLabel value="{!companyInfo.Company_Type__c}"/> <apex:outputLabel value="{!$ObjectType.Company_Info__c.Fields.Employees_Number__c.Label}" style="color: #830051;line-height: 24px;"/>
<apex:outputLabel value="{!companyInfo.Employees_Number__c}"/>
</apex:panelGrid>
</apex:pageBlock>
</apex:page>

CompanyDetailPage

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

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

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

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

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

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

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

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

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