0

I am trying to display fields and their vlues from salesforce fieldset in html table. I used the code below. I am not sure how to display the field values as I have a query in the constructor of the controller to get the required records.

I tried the below within the td tag and repeat tag

<table id="freeze-table">
    <tr>
        <apex:repeat var="f" value="{!$ObjectType.Adpub__c.FieldSets.checkfieldset}"> 
            <th>
                <apex:outputText styleClass="bold" value="{!$ObjectType.Adpub__c.Fields[f].label}"/>
            </th>
        </apex:repeat>
    </tr>
    <tr>
        <apex:repeat var="f" value="{!$ObjectType.Adpub__c.FieldSets.checkfieldset}">
            <!-- <td>
                <apex:outputField value="{!adpubs.[f.fieldpath]}" />
            </td> -->
        </apex:repeat>
    </tr>
</table>

Where abclist will contain the queried records.

I received the error message

"Error: Incorrect parameter type for subscript. Expected Number, received Text"

4
  • What's abclist? A list or a map? Can you please post some more code, the whole apex:repeat section would be helpful Mar 16, 2015 at 0:54
  • abclist is a list of abc object records. Mar 16, 2015 at 4:05
  • <table id="freeze-table"> <tr> <apex:repeat var="f" value="{!$ObjectType.Adpub__c.FieldSets.checkfieldset}"> <th><apex:outputText styleClass="bold" value="{!$ObjectType.Adpub__c.Fields[f].label}"/> </th> </apex:repeat> </tr> <tr> <apex:repeat var="f" value="{!$ObjectType.Adpub__c.FieldSets.checkfieldset}"> <!-- <td> <apex:outputField value="{!adpubs.[f.fieldpath]}" /> </td> --> </apex:repeat> </tr> </table> Mar 16, 2015 at 4:06
  • 1
    @SFDCLearner please update your question with any additional info rather than posting it in the comments. This makes it easier to understand your question. Mar 16, 2015 at 9:35

1 Answer 1

4

You need to iterate through the list, and then also through each of the fields in your field set for each of the records. So your code should look something like this (haven't tested it but it should give you an idea of how to get the desired result):

<table id="freeze-table"> 
    <tr> 
        <apex:repeat var="f" value="{!$ObjectType.Adpub__c.FieldSets.checkfieldset}"> 
            <th>
                <apex:outputText styleClass="bold" value="{!$ObjectType.Adpub__c.Fields[f].label}"/>
            </th> 
        </apex:repeat>
    </tr> 
    <apex:repeat var="adpub" value="{!adpubs}">
        <tr> 
            <apex:repeat var="f" value="{!$ObjectType.Adpub__c.FieldSets.checkfieldset}"> 
                <td>
                    <apex:outputField value="{!adpub[f]}" /> 
                </td> 
            </apex:repeat> 
        </tr> 
    </apex:repeat>
</table>
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .