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
Vijay MVijay M 

How do we access related object fields using fieldset on visualforce page

I have one custom object which has look up relationship on account. I have created fieldset on Custom object and added releted fields on account object. At the time of accessing the fieldset on VF page, i am getting an error.


Unknown property '$ObjectType.CustomObjectName.fields.Account__r'

Error is in expression '{!$ObjectType.CustomObjectName.Fields[f].localname}' in component <apex:repeat> in page condition
Error evaluating dynamic reference 'Account__r.Type'
So is it possible to access related object fields using fieldset?

Thanks in advance



ashish raiashish rai


  Well i think you bink the value of <apex:repet> with the controller value. So in that case you have to make the query on all field that you have mention inside the field set. You have to use dynamic query inside the controlle. But if you are not binding <apex:repeat> then you have you this in a simple way like this:

<apex:page standardController="Ashish_test__c">
 <apex:pageBlock id="acctDetails" title="Account Details" tabStyle="Account" >
                   <apex:pageBlockSection title="Account Information" columns="2">   
                       <apex:repeat value="{!$ObjectType.Ashish_test__c.FieldSets.MyCustomFieldSet}" var="f">       
                            <apex:outputField value="{!Ashish_test__c[f]}"/>  


It is working. Think this will help you.

Vijay MVijay M

Thanks for reply.


In addition to above, I want to access the localName of a related object fields. When i am accessing the localname of related object field using below expression then i got the above error.


<apex:repeat value="{!$ObjectType.CustomObjectName.FieldSets.FieldSet1}" var="f">

      <option value="{!$ObjectType.CustomObjectName.Fields[f].localname}">







This should work but can you check if your user has field level security access to the given field on the related object and report back here?



Vijay MVijay M

Hello Andrew,


The user has full access means, i am login as system administrator. Even though i am getting same error.









The error seems to indicate that the fieldset is returning a bad value here as you shouldn't ever just see the string end in "__r" effectively (which is why I suspected a FLS related issue initially).


I assume when you remove the fields on the related Account from the fieldset this error goes away, correct? Does this apply to all fields you try configuring in the fieldset from account or just specific one(s). If so can you indicate which ones are causing this error?

Vijay MVijay M

Hello Andrew,


I tried it for all related object fields.  it has been throwing same error. As per my understanding, whenever we add related object fields(Standard / Custom related object) in fieldset and use it on visualforce page (using above expression) then it will thow the same error.





Niraj NayanNiraj Nayan

Hi  Andrew,

I am facing the same issue. As Vijay said its due to adding fields of related object to the field set.


For example – I have two objects Incident_c and Broadcast__c. And Broadcast__c is a lookup on Incident__c. When I add Broadcast > Name to the Incident’s fieldset ,throws an error –


Unknown property '$ObjectType.Incident__c.fields.FKBroadcast__r'
Error evaluating dynamic reference 'NAYAN__FKBroadcast__r.Name'




Phil Jones 10Phil Jones 10
Does anyone know if localname is prefixed with a namespace when packaged?