In a visualforce page I can get a list of child records directly (without any query) using the child relationship name like {!ParentObject__c.Child_Relationship_name__r} and this list is of the type of the Child Object.

<apex:page standardController="ParentObject__c">
     <apex:repeat value="{!ParentObject__c.Child_Relationship_name__r}" var="child">
         {!child.Name}//Or any field


This brings me to my problem, when I have a visualforce component that has an attribute of type ChildObject__c[] that I assign to a property in the component's controller of the same type I get the error

Cannot convert the value of '{!childList}' to the expected type.

But if instead of using the relationship list I construct a list of ChildObject__c (i.e. List<ChildObject__c>) with a query, it works as expected and the list gets displayed.



public with sharing class Component_Ctrl {
    public List<ChildObject__c> childList {get;set;}


<apex:component controller="Component_Ctrl">
    <apex:attribute name="children" type="ChildObject__c[]" description="A list of child objects for the component assignTo="{!childList}" required="true"/>
    <apex:repeat value="{!childList}" var="child">
         {!child.Name}//Or any field


<apex:page standardController="ParentObject__c">
     <c:Comp children="{!ParentObject__c.Child_Relationship_name__r}"/><!--Here I get the error-->
     <!--<c:Comp children="{!children}"/>--><!--This one works when children is constructed from a query-->

I already have the query workaround implemented, but I want to understand why the first option fails, I want to avoid that extra query.

  • 1
    Seems to be a bug that has yet to be solved. Most likely because SF does not let us submit bugs unless we pay for premier support: salesforce.stackexchange.com/questions/57214/… – Eric Dec 20 '16 at 16:41
  • Yes @Eric, it looks like a bug, I missed that question. – Jose Dec 20 '16 at 16:48

Your Answer

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

Browse other questions tagged or ask your own question.