두 Salesforce 테이블 이름이 주어지면 두 테이블 사이에 상위/하위 관계가 있는지, 그리고 관계가 존재하는 테이블이 상위인지 확인하고 싶습니다. .Salesforce API : 두 임의 테이블 간의 관계를 확인하는 방법이 있습니까
나는이 방법을 간단한 경우와 함께 사용할 수 있지만 최악의 경우 두 테이블의 모든 하위 관계를 검토해야하므로 최적화되지 않았습니다. 나는 또한이 접근법이 모든 경우를 다루고 있다고 확신하지 못한다.
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.");
}
더 좋은 방법이 있나요?