function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vfnevfne 

STUCK ON BASIC! outputField can only be used with SObject fields

Hello,

 

i am trying to get fields from the parent custom object that i have created (Client), the child relationship name is "ActivitesClient__r" but i keep on getting 


Error: Could not resolve the entity from <apex:outputField> value binding '{!c.ActivitesClient__r.Value_in_2009__c}'. outputField can only be used with SObject fields.

 

i have tried replacing apex:outputField with outputText but i goto the following error: Error: Unknown property 'VisualforceArrayList.Value_in_2009__c

 

Value_in_2009__c is a custom field and set as a Text

 

here is the code

 

<apex:page standardController="Client__c" >
    <apex:variable value="{!Client__c}" var="c" />
    <apex:form >
      <apex:pageBlock title="Activities">
          <apex:pageblocksection >
             <apex:outputField value="{!c.Name}" />
             <apex:outputField value="{!c.Chiffre_aff__c}" />
             <apex:outputField value="{!c.ActivitesClient__r.Value_in_2009__c}" />
          </apex:pageblocksection>
      </apex:pageBlock>
     </apex:form>
</apex:page>

 

I dont have any idea why is this not working? I am referring a text using the childrelationship name..

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

You should be able to do use output fields for the referenced object, here's an example from one of my pages:

 

 

<apex:outputField value="{!Candidate__c.Account__r.Name}" />

 

 

and this displays the account name as expected.

 

In your situation, is the related object a parent (i.e. does Client__c have a lookup field with an API name of ActivitesClient__r) or is Client__c the parent and ActivitesClient__r is a related list?

 

If its the latter, then you won't be able to refer to a field in that way, rather you'd need to iterate the related objects and output the detail for each one,  e.g.

 

 

<apex:page standardController="Client__c" >
    <apex:variable value="{!Client__c}" var="c" />
    <apex:form >
      <apex:pageBlock title="Activities">
          <apex:pageblocksection >
             <apex:outputField value="{!c.Name}" />
             <apex:outputField value="{!c.Chiffre_aff__c}" />
             <apex:dataTable value="{!c.ActivitesClient__r}" var="act">
                <apex:column value="{!act.Value_in_2009__c}"/>
             </apex:dataTable>
          </apex:pageblocksection>
      </apex:pageBlock>
     </apex:form>
</apex:page>

 

 

 

 

All Answers

kiranmutturukiranmutturu

outfield will refer to the object's field only not the referenced object.....

vfnevfne

ok so do i need to cast this referenced object to a objectField ? or there is another fix.. 

kiranmutturukiranmutturu

why can't u use outputtext there...

bob_buzzardbob_buzzard

You should be able to do use output fields for the referenced object, here's an example from one of my pages:

 

 

<apex:outputField value="{!Candidate__c.Account__r.Name}" />

 

 

and this displays the account name as expected.

 

In your situation, is the related object a parent (i.e. does Client__c have a lookup field with an API name of ActivitesClient__r) or is Client__c the parent and ActivitesClient__r is a related list?

 

If its the latter, then you won't be able to refer to a field in that way, rather you'd need to iterate the related objects and output the detail for each one,  e.g.

 

 

<apex:page standardController="Client__c" >
    <apex:variable value="{!Client__c}" var="c" />
    <apex:form >
      <apex:pageBlock title="Activities">
          <apex:pageblocksection >
             <apex:outputField value="{!c.Name}" />
             <apex:outputField value="{!c.Chiffre_aff__c}" />
             <apex:dataTable value="{!c.ActivitesClient__r}" var="act">
                <apex:column value="{!act.Value_in_2009__c}"/>
             </apex:dataTable>
          </apex:pageblocksection>
      </apex:pageBlock>
     </apex:form>
</apex:page>

 

 

 

 

This was selected as the best answer
vfnevfne

This code did not work for me returning "outputField can only be used with SObject fields":

 

<apex:outputField value="{!Candidate__c.Account__r.Name}" />

 

In my case, Client__c is the parent. 

 

Your solution worked, but meanwhile i used the apex:repeat to iterate over the ArrayList:

 

<apex:repeat var="rep" value="{!c.ActivitesClient__r}">

 

 

and then use it directly in a td:

 

<td class="dataCell">{!rep.Nombre_d_Appel_Offre_en_2011__c}</td>

 

I also tried your solution and it works like a charm, thanks a lot !