SalesforceAPI:有没有办法确定两个随机表之间的关系
给定两个Salesforce表名,我想确定它们之间是否存在父/子关系,以及该关系是否存在,哪个表是父表 我有这个方法可以处理简单的情况,但它没有优化,因为在最坏的情况下,我必须遍历两个表的所有子关系。我也不相信这种方法能处理所有情况SalesforceAPI:有没有办法确定两个随机表之间的关系,salesforce,Salesforce,给定两个Salesforce表名,我想确定它们之间是否存在父/子关系,以及该关系是否存在,哪个表是父表 我有这个方法可以处理简单的情况,但它没有优化,因为在最坏的情况下,我必须遍历两个表的所有子关系。我也不相信这种方法能处理所有情况 private String getParent(String table1, String table2) throws Exception { DescribeSObjectResult[] describeSObjectResults =
private String getParent(String table1, String table2) throws Exception
{
DescribeSObjectResult[] describeSObjectResults =
pc.describeSObjects(new String[] {table1, table2});
// Child relationships of table1
for (ChildRelationship cr : describeSObjectResults[0].getChildRelationships())
{
// table1 has a child matching table2
if (table2.equalsIgnoreCase(cr.getChildSObject()))
{
return table1;
}
}
// Child relationships of table2
for (ChildRelationship cr : describeSObjectResults[1].getChildRelationships())
{
// table1 has a child matching table2
if (table1.equalsIgnoreCase(cr.getChildSObject()))
{
return table2;
}
}
throw new Exception("There is no parent/child relationship.");
}
有更好的方法吗?我不确定我会在这里改变什么。理解和维护代码非常简单、清晰 您可以只描述一个对象,从“下”到子关系,从“上”到检查所有字段,并检查像
getReferenceTo()
这样的方法是否返回有意义的内容
但我不会这么做:
可以指向Case.OwnerId
或User
Queue
可以指向勾选了“允许活动”的任何对象Event.WhoId
可以指向Report.ParentId
、文件夹
或用户
组织
抛出异常位)
您可以尝试在数据库中预填充一些helper表,然后引用这些缓存数据
您可以尝试为您的组织缓存一个“企业WSDL”副本,我相信每次扫描本地保存的XML都要比go&ask SF快(您需要记得每隔一段时间获取一个新副本)。您甚至可以将其组合为“本地数据库作为从WSDL生成的缓存,如果找不到,则进行昂贵的描述调用”