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
sfdc guy.ax723sfdc guy.ax723 

Fieldsets in a Datatable

I am trying to use Dynamic Field Binding with in a datatable.

 

I want to send a List of Tasks from a query to a datatable to be rendered, but be able to add columns to the table using a fieldset defined in Task Field Sets.

 

Here is my code:

 

<apex:dataTable cellspacing="2" value="{!Tasks}" var="ta" rendered="{!HasActivities}" id="Results3" rowClasses="odd,even">
        <apex:column headerValue=""><apex:outputLink value="/{!ta.Id}" target="_blank">View</apex:outputLink></apex:column>
        <apex:column headerValue=""><apex:outputLink value="/{!ta.Id}/e?" target="_blank">Edit</apex:outputLink></apex:column>

        <apex:repeat value="{!$ObjectType.Task.FieldSets.TaskMassEditFieldSet}" var="f">
              <apex:column headerValue=""><apex:inputField value="{!ta.[f]}" /></apex:column>
        </apex:repeat>
</apex:dataTable>

 

!Tasks is my list of Tasks.

 

When I try to save the page I get an "Invalid field for SObject Task" Error


 

Is this possible?

 

Thanks in advance for any help.

Best Answer chosen by Admin (Salesforce Developers) 
aballardaballard

The syntax for the dynamic field reference should be {!ta[f]},  not {!ta.[f]}

All Answers

aballardaballard

The syntax for the dynamic field reference should be {!ta[f]},  not {!ta.[f]}

This was selected as the best answer
RajiRaji

Hi that's not working please once confirm this . actually its getting displayed null

 

please find the below my controller and Pages

public with Sharing Class FieldsetController{
    public contact con1;
    public FieldsetController(apexpages.standardcontroller con){
        this.con1=(contact)con.getRecord();
    }
    list<Contact> lstcon;
    public list<Contact> getlstContact(){
        lstcon=[select id,lastname,email,firstname,department from Contact limit 5];
    return lstcon;
    }
}
<apex:page id="pageId" standardcontroller="contact" extensions="FieldsetController" >  
<apex:form id="formId">  
    <apex:pageblock id="pbId">  
        <apex:pageblocksection columns="1" id="pbsIs">
         <apex:datatable value="{!lstcontact}" var="con" >
                <apex:Column  value="{!con.lastname}" /> 
                <apex:repeat value="{!$ObjectType.contact.FieldSets.testFieldsets}" var="f">  
                    <apex:inputfield value="{!con.[f]}">  
                </apex:inputfield></apex:repeat> 
         </apex:datatable> 
        </apex:pageblocksection>  
    </apex:pageblock>  
</apex:form>  
</apex:page>  

 Advance Thanks 

 

 

 

 

Sumitkumar_ShingaviSumitkumar_Shingavi
Did you got this working? Can you confirm solution for this?
Sumitkumar_ShingaviSumitkumar_Shingavi
I think
<apex:inputfield value="{!con.[f]}">
Should be
<apex:inputfield value="{!con[f]}">