How to get list of Objects Master detail with account? 这个问题未完待续
参考自:How to get list of Objects Master detail with account. 但下述这个方法拿到的是系统内的所有Object,需要自己做一遍筛选。
PS: 即使是Lookup关系,isCascadeDelete 字段为true的时候,在Account删除时,该Object也是会被删除的
//this example describes the Account sObject
Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe(); //the master object. In this scenario it is Account
List<Schema.ChildRelationship> C = R.getChildRelationships();
Set<Schema.SObjectType> childNameList = new Set<Schema.SObjectType>();
Integer countDetailObjectsRelatedToMaster= 0;
String childName;
for( Schema.ChildRelationship sc :c){
if(sc.isCascadeDelete()){ //this means it is master-detail
if (sc.getRelationshipName() != null){
countDetailObjectsRelatedToMaster++;
System.debug('getChildSObject: ' + sc.getChildSObject());
System.debug('getField: ' + sc.getField());
System.debug('getRelationshipName: ' + sc.getRelationshipName());
System.debug('isRestrictedDelete(): ' + sc.isRestrictedDelete());
}
}
}
System.debug('countDetailObjectsRelatedToMaster: '+countDetailObjectsRelatedToMaster);
附上另一篇文章:Guidelines for Deleting Accounts
对于Lookup字段,我们目前有2个选项,如果想Enable Cascade Delete需要联系Salesforce启用,默认是Disable的,参考下图:
image.png
网友评论