+ Start a Discussion
aatish sharmaaatish sharma 

hi i have problem i want to get all child records by using standard controller of custom object

how to get child from from parent
Best Answer chosen by aatish sharma
Alex EzhilarasanAlex Ezhilarasan
Yes Aatish. But you can get the list by extensions. Check the codes below.

Page
<apex:page standardController="Custom_Object__c" extensions="TempDeleteController">
  <apex:repeat value="{!childContact}" var="c" >
      {!c.Name}
  </apex:repeat>
</apex:page>
Apex class
public class TempDeleteController{
    
    public List<Contact> childContact{get; set;}
    private final Custom_Object__c co;

    public TempDeleteController( ApexPages.StandardController stdController ){
        
        this.co = (Custom_Object__c)stdController.getRecord();
	    childContact = new List<Contact>();
        
        for( Contact c: [SELECT Id,Name FROM Contact WHERE Custom_Object__c = :co.Id ] ){
            
            childContact.add(c);
        }
    }
}


 

All Answers

Alex EzhilarasanAlex Ezhilarasan
Hi Aatish,

Try 
<apex:repeat value="{!Expense__c.Contacts}" var ="c">

Thanks,
Alex 
aatish sharmaaatish sharma
[image: Inline image 1] i tried this already still same problem [image: Inline image 2]
aatish sharmaaatish sharma
i have already try this but still same issue
Alex EzhilarasanAlex Ezhilarasan

Hi Aatish,

Please check the child relationship name in Contact object. (Open Lookup/Master-Detail field-There you can see Child Relationship value)

I checked with Account and Contact relationship. It is working for me.User-added image
Field is
User-added image

Check the Child Relationship Name and use that
 

aatish sharmaaatish sharma
 hi alex problem solved , actually i was trying to make standard contact object as child of custom object but when i take custom object child different custom object then its work fine for me. thanks for your help
aatish sharmaaatish sharma
yes, i just wanted to confirm with you can we make a standard object such as contact as a child of custom object, and then can get the standard object object as child in query if yes. then problem still there because i used custom object now, and its become parent and child both custom object now, but when parent is custom and child is standard then i  cant fetch the query from the soql. why?
Alex EzhilarasanAlex Ezhilarasan
Yes Aatish. But you can get the list by extensions. Check the codes below.

Page
<apex:page standardController="Custom_Object__c" extensions="TempDeleteController">
  <apex:repeat value="{!childContact}" var="c" >
      {!c.Name}
  </apex:repeat>
</apex:page>
Apex class
public class TempDeleteController{
    
    public List<Contact> childContact{get; set;}
    private final Custom_Object__c co;

    public TempDeleteController( ApexPages.StandardController stdController ){
        
        this.co = (Custom_Object__c)stdController.getRecord();
	    childContact = new List<Contact>();
        
        for( Contact c: [SELECT Id,Name FROM Contact WHERE Custom_Object__c = :co.Id ] ){
            
            childContact.add(c);
        }
    }
}


 
This was selected as the best answer