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
Tobias HaggeTobias Hagge 

apex:repeat all fields from Object


I would like to render all fields in a VF page and I think the repeat function might be the easiest.
<apex:repeat value="{!$ObjectType.Account.Fields.}" var="f">
            <apex:outputfield value="{!Account[f]}"> 
I am missing the last bit though. Is that achievable, or would it need a class that gets all fields and then the repeat function referencing it?

deva mdeva m
Hi Tobias Hagge

give the name and description
and drag fields that you want and save it.

Then write thiscode 

  <apex:repeat value="{!$ObjectType.task.Account.fieldsetname}" var="f">                                          
                                        <apex:inputfield value="{!Account[f]}" />

Will work
Jerome LusinchiJerome Lusinchi
I suggest you to create a field set in account and add all the fields that you want to use in this VF.
Then this is the code of your VF

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

Hope this helps
Tobias HaggeTobias Hagge
The problem for that is that I want to have every single field to be in there (no exception) and this are over 300. Also I would not have to add fields manually to the field set every time I create a new field.
Jerome LusinchiJerome Lusinchi
Then you'll have to do it with Apex,

SObjectType accountType = Schema.getGlobalDescribe().get('Account');
Map<String,Schema.SObjectField> mfields = accountType.getDescribe().fields.getMap();

Tobias HaggeTobias Hagge
Gives the following error message:
SObject row was retrieved via SOQL without querying the requested field: Account.Account_ID__c

Account_ID__c is a custom formula field. I assume that the function has a general problem with formula fields? Is there a good way to exclude the formula field type from the expression?

Jerome LusinchiJerome Lusinchi
can you share your code.
what do you want to display in your VF in the end ? the list of fields of Account Object ?

List<String> AccountFields {get; set;}

AccountFields = new List<String>();
Map<String, Schema.SObjectField> schemaFieldMap = Schema.SObjectType.Account.fields.getMap();
for(String MyFieldName : schemaFieldMap.keyset()){

then you use this list in you VF, with
<apex:repeat value="{!AccountFields}" var="field">
     <apex:outputText value="{!field}"/><br></br>

Tobias HaggeTobias Hagge
Thanks for the help. Hopefully we can find a fix.
public Map<String, Schema.SObjectField> all_fields {get; set;}

all_fields = getFields();

    public List<String> getFields()
		Map<String,Schema.SObjectField> mfields = accountType.getDescribe().fields.getMap();
		List<String> fieldNames = List<String>();
    	for(String field: mfields.keySet())
        return fieldNames;