在Salesforce中可以向Object所對應的Layout中添加我們自定義的Visualforce Page。 此時的Visualforce Page與Asp.Net MVC中的Partial View有着異曲同工的妙處。
那么如何完成整個流程呢?請看如下操作步驟:
1):在自定義的Visualforce Page中要添加如下標簽
【standardController標志此Page可以添加到哪個Object所對應的Layout中】
【extensions指定了對應的后台Class文件】
<apex:page standardController="Account" extensions="CreditLimitController">
2):處理后台的Class文件,完成我們所需要的特定邏輯
【ApexPages.StandardController與Page中指定的standardController向對應】
【(Account)controller.getRecord()獲取了當前操作的Object,這里指向的是Account,實質上獲取的是該對象的id,若要獲取其他更加詳細的信息,需要根據id進行query】
public class CreditLimitController { //added an instance varaible for the standard controller private ApexPages.StandardController controller {get; set;} // the actual account private Account a; public CreditLimitController(ApexPages.StandardController controller) { //initialize the stanrdard controller this.controller = controller; this.a = (Account)controller.getRecord(); system.debug('---------002Account Id ' + this.a.Id); } }
3):上2個步驟已經將自定義的Visualforce Page准備完畢,接下來我們進入Account所對應的Page Layout中,如下圖所示
4):點擊上圖的Edit按鈕,在Fields中找到Section,手動拖拽一個Section到指定的位置
5):在Visualforce Pages中我們可以看到我們剛剛創建的Page(CreditLimit),然后用拖拽的方式將此Page添加到剛剛添加的Section中
這樣我們就完成了將自定義的Visualforce Page添加到指定的Page Layout中。
更多詳細的內容,請看如下鏈接:
http://blog.jeffdouglas.com/2009/05/08/inline-visualforce-pages-with-standard-page-layouts/
http://blogs.developerforce.com/systems-integrator/2008/11/adding-a-visualforce-page-to-a-page-layout.html
http://help.salesforce.com/apex/HTViewSolution?id=000004503&language=en_US