給定兩個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.");
}
有沒有更好的方法來做到這一點?