如何使用VF或APEX獲取相關列表,當我們通過URL傳遞ID和對象時,Ex假設我發送Account對象和ID,我應該只獲取與Account對象相關的列表,但不能獲取Account details 。如果我使用APEx:詳細信息我將獲得帳戶和它的相關列表,但我只需要相關列表。僅在salesforce中使用的相關列表
@Ivan這裏的代碼
控制器
Public Class CustomRelatedList{
public String objectType {get; set;}
public Set<String> chsobject1 {get;set;}
public sobjecttype chsobject {get;set;}
public sObject[] data {get; set;}
public CustomRelatedList() {
chsobject1 = new Set<String>();
}
public void CustomRelatedList1() {
//get URL parameters
//的objectType = ApexPages.currentPage()getParameters()得到( 'urlparm')。;
objectType = ‘Account’; //for testing purpose will get object type & Id from URL
Map<String , Schema.SObjectType> globalDescription = Schema.getGlobalDescribe();
Schema.sObjectType sObjType = globalDescription.get(objectType);
Schema.DescribeSObjectResult r1 = sObjType.getDescribe();
List<Schema.ChildRelationship> C = r1.getChildRelationships();
for (Schema.ChildRelationship C1:C) {
chsobject = C1.getChildSObject();
chsobject1.add(String.valueof(chsobject));
}
}
}
VF page
<apex:page controller="CustomRelatedList" >
<apex:repeat value="{!chsobject1}" var="a" >
<apex:relatedList list="{!a}" subject="{!$CurrentPage.parameters.id}" />
</apex:repeat>
</apex:page>
我想顯示的ID(不只是名稱)的所有相關的清單,但參數列表中只需要文字
謝謝它的工作:-) – user3589895
酷:)請考慮在幾天的時間接受答案。這樣,你可以給予其他人幾天更多的聰明才智,但最終這些問題很有可能會被「忽略」。 – eyescream