Instead of teacher__c and student__c, they needs be dynamic variables. How can I substitute these API names with variables: parentApiName
and childApiName
?
for (ChildRelationship relation : SObjectType.teacher__c.getChildRelationships())
if (relation.getChildSObject() == student__c.sObjectType)
system.debug(relation.getRelationshipName());
What I tried and failed:
for (ChildRelationship relation : SObjectType.${parentApiName}.getChildRelationships())
if (relation.getChildSObject() == `${childApiName}.sObjectType`)
system.debug(relation.getRelationshipName());