I have a Visualforce component where I am trying to get a related list (children) of any record (say Account, depends on the value I give in my VF page). I have two attributes in my VF component, objectName
which gets the parent object and childRelationshipName
which gets the child relationship name.
In my VF page the parent is Account and childRelationshipName
is Contacts (any custom object child relationship name).
In RecordDisplayController
, the controller for the VF component, I am trying to get the child relationship name specified in the childRelationshipName
tag of the VF page. But in my code I was able to get all the child relationship names related to the parent.
Is there a way to get only the child relationship name of that particular API name which is mentioned in the VF page?
VF component:
<apex:component controller="RecordDisplayController">
<apex:attribute name="objectName" description="An Sobject" type="Sobject" required="false" assignTo="{!objectvar}"/>
<apex:attribute name="childRelationshipName" description="Child Object" type="String" required="false" assignTo="{!childrelationship}"/>
</apex:component>
RecordDisplayController:
public class RecordDisplayController {
public sObject objectvar;
public String childrelationship;
public void setobjectvar(sObject s) {
objectvar = s;
DescribeSObjectResult describe = objectVar.getSObjectType().getDescribe();
for (Schema.ChildRelationship child : describe.getChildRelationships()) {
System.debug('===================> relationship name ' + child.getRelationshipName());
System.debug('===================> field name ' + child.getField());
}
}
public sObject getobjectvar() {
return objectvar;
}
public void setchildrelationship(String s) {
childrelationship = s;
}
public String getchildrelationship() {
return childrelationship;
}
}
VF page:
<apex:page standardController="Account">
<c:recorddisplay childRelationshipName="Invoices" objectName="{!Account}" />
</apex:page>