仅限salesforce中的相关列表

仅限salesforce中的相关列表,salesforce,visualforce,apex,Salesforce,Visualforce,Apex,如何使用VF或APEX仅获取相关列表,当我们通过URL传递ID和对象时,例如假设我发送帐户对象和ID,我应该只获取帐户对象相关列表,而不获取帐户详细信息。如果我使用APEx:Detail,我将获得帐户及其相关列表,但我只需要相关列表 @伊凡,这是密码 控制器 Public Class CustomRelatedList{ public String objectType {get; set;} public Set<String> chsobject1 {get;set;}

如何使用VF或APEX仅获取相关列表,当我们通过URL传递ID和对象时,例如假设我发送帐户对象和ID,我应该只获取帐户对象相关列表,而不获取帐户详细信息。如果我使用APEx:Detail,我将获得帐户及其相关列表,但我只需要相关列表

@伊凡,这是密码

控制器

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
公共类CustomRelatedList{
公共字符串对象类型{get;set;}
公共集chsobject1{get;Set;}
公共sobjecttype对象{get;set;}
公共sObject[]数据{get;set;}
公共CustomRelatedList(){
chsobject1=新集合();
}
public void CustomRelatedList1(){
//获取URL参数
//objectType=ApexPages.currentPage().getParameters().get('urlparm')

objectType='Account';//出于测试目的,将从URL获取对象类型和Id
Map globalDescription=Schema.getglobaldescripe();
Schema.sObjectType-sObjType=globalDescription.get(objectType);
Schema.DescribeSObjectResult r1=sObjType.getDescribe();
List C=r1.getChildRelationships();
for(Schema.ChildRelationship C1:C){
chsobject=C1.getChildSObject();
chsobject1.add(String.valueof(chsobject));
}
}
}
VF页面

我想显示Id的所有相关列表(不仅仅是名称),但参数列表只接受文字

我想你在寻找

我会欺骗并隐藏我不想使用CSS的页面块;)这不是一个聪明的Apex'y解决方案,但它处理了太多的东西(用户不应该看到的对象和列表,页面布局与他的个人资料和选定的记录类型一致等等)

从如下页面开始:


全局变量,但当我使用
{!$Component.detail}
..

谢谢Ivan..假设我通过URL发送任何通用对象(可以是自定义或标准对象)和Id,并且它应该只显示相关列表您可以使用
DescribeSObjectResult.GetChildRelations()
在控制器中生成可用关系列表,然后使用
在页面上对其进行迭代,我能够获得子关系,但当尝试使用它显示这些子关系的相关列表时,给出以下错误错误:中的属性列表需要文本值,是否有任何方法显示这些相关列表请向我们提供您目前正在使用的控制器和VF代码。如果你觉得你原来的问题被回答了,你现在面临着不同的问题,也可以考虑单独做一个问题。酷:请考虑在几天内接受答案。这样一来,你就可以多给别人几天时间,让他们想出一些聪明的办法,但最终,这些问题还是可以“不被关注”的。
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>