0

I am building a visualforce component where I have:

 <apex:attribute name="objectName" description="An Sobject" type="Sobject" required="false"/>  
<apex:attribute name="ChildName" description="Child Relationship" type="String" required="false"/>

I would like to refer "objectName" in my Visualforce page like:

<apex:page standardController="Account" recordSetVar="acc">   
<c:recorddisplay childName="Account" objectName="{!acc}"/>
</apex:page>

But when I try to use objectName="{!acc}" in my VF page it says:

<c:recorddisplay objectName="{!acc}">. Expected Sobject, found Account[]

  • 1
    Can you post your controller? You're doing things the right way but it seems as though your controller doesn't have a property called Contact. Are you using a standard controller? – Matt Lacey Apr 27 '16 at 0:17
  • I am using - <apex:page standardController="Account" recordSetVar="acc">, Just added it. But when I try to use objectName="{!acc}" in my VF page it says - <c:recorddisplay objectName="{!acc}">. Expected Sobject, found Account[] – SfdcBat Apr 27 '16 at 0:19
  • 1
    Updated your quesiton based on your comment. For the original issue with "Contact" not being allowed, accounts don't have a Contact property, but they do have Contacts (plural). You'd need to loop over Account.Contacts in a similar manner to the Account loop in my answer. – Matt Lacey Apr 27 '16 at 0:27
2

So your problem is you're using a Standard List Controller, which deals with multiple records as opposed to a Standard Controller which operates on a single SObject.

The variable you assign to the recordSetVar parameter is an array of objects of the type specficied, so in your case acc is an array of accounts, hence the mismatched type error.

You can either ditch the recordSetVar="acc" property if you just want to work with one account and do:

<c:recorddisplay objectName="{!Account}"/>

or loop over the accounts:

<apex:repeat value="{!acc}" var="a">
    <c:recordddisplay objectName="{!a}"/>
</apex:repeat>

objectName doesn't seem like a great name for the parameter, consider calling it record or something instead.

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.