0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AuraDefinitionBundleとAuraDefinitionとの子リレーション名

Posted at

AuraDefinitionオブジェクトにはAuraDefinitionBundleIdtという参照フィールドがあるのでAuraDefinitionBundleオブジェクトとは親子の関係だと思っていいでしょう。

といういうことは子リレーション名が分かれば以下のように検索できると思っています。

select Id , (select Id, from 子リレーション名) from AuraDefinitionBundle

しかし見つからないんですよね。
AuraDefinitions かなぁって思ったけどエラーになる。

子リレーション名を探すいい方法はないかと調べてみると...
よさげなApex Classが紹介されている。

2つのメソッドが紹介されているけど、結果は同じみたい。


        //Create sobject Instance 
        sObject dynamicObj = (SObject)Type.forName(parentsObj).newInstance();
        //get the type token
        SObjectType sObjType = dynamicObj.getSObjectType();
        //get describe
        DescribeSobjectResult sObjDescribe = sObjType.getDescribe();
        //loop through children
        for(Schema.ChildRelationship rels :sObjDescribe.getChildRelationships()){
            //find the child
            if(String.ValueOf(rels.getChildSObject()) == childsObj){
                return rels.getRelationshipName();
            }
        }
        return null;
    }
public static Map<String, ChildRelationship> getChildRelationshipMap(String parentsObj){

        Map<String, ChildRelationship> sObjChildRelationshipName = new Map<String, ChildRelationship>();
        //Create sobject Instance 
        sObject dynamicObj = (SObject)Type.forName(parentsObj).newInstance();
        //get the type token
        SObjectType sObjType = dynamicObj.getSObjectType();
        //get describe
        DescribeSobjectResult sObjDescribe = sObjType.getDescribe();
        //loop through children
        for(Schema.ChildRelationship rels :sObjDescribe.getChildRelationships()){
            //put the child in map
            sObjChildRelationshipName.put(String.ValueOf(rels.getChildSObject()), rels);
        }
        return sObjChildRelationshipName;
    }

でわ、早速調べてみますか?

system.debug(fkd_common.getChildRelationshipName('AuraDefinitionBundle', 'AuraDefinition'));

>null

system.debug(fkd_common.getChildRelationshipMap('AuraDefinitionBundle').get('AuraDefinition').getRelationshipName());

>null

えええ、結果はnull。子リレーション名が無いってこと。何でだ?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?