Getting Child Relationship Names using Apex

Getting Child Relationship Names using Apex

For any object if you want to know child relationships associated to it?
Check following snippet

Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();
for(Schema.ChildRelationship cr: R.getChildRelationships()){
    system.debug('Relationship Name =>'+cr.getRelationshipName());
}

NOTE: Please replace Account in first line with sObject which you want to get child relationship names

Subscribe to Phanindra Mangipudi

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe