Been looking around for an alternative to manually writing the Api Field Name to display the data in an sObject List.

Normal Example:

<apex:repeat value="{!myCustomObjectList}" var="co">
     <apex:outputText value="co.customObjectFieldApiName1__c" />
     <apex:outputText value="co.customObjectFieldApiName2__c" />
     <apex:outputText value="co.customObjectFieldApiName3__c" />

Instead of doing this for each row was playing around with using a List<String> of the field Api Names and iterating through that within the repeat.

Example (of what I'm trying to do):

In Controller:

List<String> customObjApiFieldNames = new List<String>

for (String s : schemaFieldSet) {
    SObjectField fieldToken = schemaFields.get(s);
    DescribeFieldResult selectedField = fieldToken.getDescribe();

In VF Page:

<apex:repeat value="{!myCustomObjectList}" var="co">
     <apex:repeat value="{!customObjApiFieldNames}" var="coField">
         <apex:outputText value="co.coField" />

Of course this example doesn't work, so am looking for something along similar lines.


This will work you just need to change it little bit. For dynamic iteration of fields we pass them is sObject. This is similar with map iteration on visualforce.

  <apex:outputText value="co[coField]" />

The only thing you need to make sure here is you provide correct API name

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.