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 :)

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

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.