3

The input is going to be a String containing the parent object name (say, Custom_Parent__c) and I would like the method to return me the names of ALL of its child objects (the output format doesn't matter... List, comma separated, etc are all OK).

How can this be done? Thank you :)

1 Answer 1

3
Set<String> results = new set<String>();
for( ChildRelationship r: Custom_Object__c.SObjectType.getDescribe().getChildRelationships())
    results.add(string.valueOf(r.getChildSObject()));
System.debug(string.join(new List<String>(results),',');

This outputs a comma delimited list of related objects. See documentation for more details on ChildRelationship.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .