【探索Apex开发之】如何找出所有关联的子表, 确认关系
2023年09月20日
文章浏览:246

如题,使用Apex代码实现:

Schema.DescribeSObjectResult describeResult = YourObjectName__c.sObjectType.getDescribe();
List<Schema.ChildRelationship> childRelationships = describeResult.getChildRelationships();

for(Schema.ChildRelationship childRel : childRelationships) {
    if(childRel.getField().getDescribe().isNamePointing() == false) {
        Schema.DescribeSObjectResult childDescribe = childRel.getChildSObject().getDescribe();
        String childObjectLabel = childDescribe.getLabel();
        String fieldLabel = childRel.getField().getDescribe().getLabel();
        System.debug('@@@@@Child Object Label: ' + childObjectLabel + ', API Name: ' + childRel.getChildSObject() + ', Field API Name: ' + childRel.getField().getDescribe().getName() + ', Field Label: ' + fieldLabel);
    }
}

YourObjectName__c换成你的对象名,之后在Developer Console的匿名块中执行即可,结果会出现在Log里。

关注 收藏