0

I get following error in my vf page:

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

Please share some thoughts, below is snippet from my page.

<apex:repeat value="{!selectedRecords}" var="recs">
    <tr class="dataRow">
        <apex:repeat value="{!selectedFields}" var="fieldName">
            <td>
                <apex:outputField value="{!recs[fieldName]}"/>
            </td>
        </apex:repeat>
    </tr>    
</apex:repeat>

Controller : Please find below controller code

public class FieldSelectionController {

public SelectOption[] selectedFieldList      { get; set; }
public Account[] selectedTrackers     { get; set; }
public String[] selectedTrackerIdList        { get; set; }
public Set<String> selectedFields            { get; set; }
public Boolean exportExcel                   { get; set; }
public Map<String,String> fieldNameToValueMap{ get; set; }

public FieldSelectionController(){
    init();
    selectedFieldList = getDefaultSelectOptions();        
    String selectedRecords = ApexPages.currentPage().getParameters().get('selectedRecordsIdJSON');
    selectedTrackerIdList = (List<String>)JSON.deserialize(selectedRecords, List<String>.class);
}


private void init() {
    exportExcel = false;
    selectedFields = new Set<String>();
}


private List<SelectOption> getDefaultSelectOptions() {
    List<Schema.FieldSetMember> fieldSet = SObjectType.Account.FieldSets.Export_Default_Fields.getFields();
    List<SelectOption> defaultOptions = new List<SelectOPtion>();
    for(Schema.FieldSetMember fieldMember:fieldSet) {
        selectedFields.add(fieldMember.getFieldPath().toLowerCase());
        defaultOptions.add(new SelectOption(fieldMember.getFieldPath(),fieldMember.getLabel()));
    }
    return defaultOptions;
}

public List<SelectOption> availableFields 
{
    get{
        if(this.availableFields == null) {
            availableFields = new List<SelectOption>();
            Map<String,String> fieldListMap = getFieldList();
            for(String fieldName:fieldListMap.keySet()) {
                if(!selectedFields.contains(fieldName)) {
                    availableFields.add(new SelectOption(fieldName,fieldListMap.get(fieldName)));                        
                }
            }
        }
        return availableFields;
    }set{}        
}

private Map<String,String> getFieldList() {
  fieldNameToValueMap = new Map<String,String>();
  Map<String, Schema.SObjectField> fieldMap = Schema.SObjectType.Account.fields.getMap();
  for(String fieldApiName:fieldMap.keySet()) {
    Schema.DescribeFieldResult fieldDescResult = fieldMap.get(fieldApiName).getDescribe();
    String fieldLabel = fieldDescResult.getLabel();
    fieldNameToValueMap.put(fieldApiName,fieldLabel);
  }
  return fieldNameToValueMap;
} 

public void ExportToExcel() {
    //System.debug('--select options--'+selectedFieldList);
    exportExcel = true;
    selectedTrackers = getSelectedTrackersInfo();
}

private List<Account> getSelectedTrackersInfo() {   
    List<Account> result = new List<Account>();
    retriveFieldNamesAsString();
    String fieldList = '';
    for(String fieldName:selectedFields) {
        fieldList += fieldName+',';
    }
    fieldList = fieldList.removeEnd(',');
    String whereClauseFilterOne = '';
    for(String trackerId:selectedTrackerIdList) {
        whereClauseFilterOne += '\''+trackerId+'\''+',';
    }
    whereClauseFilterOne = whereClauseFilterOne.removeEnd(',');
    if(String.isNotBlank(fieldList) && String.isNotBlank(whereClauseFilterOne)) {
        String query = 'SELECT '+fieldList+' From Account Where Id in ('+whereClauseFilterOne+')';
        result = (List<Account>)Database.query(query);
    }
    return result;
}

private void retriveFieldNamesAsString() {
    selectedFields.clear();
    for(SelectOption option:selectedFieldList) {
        selectedFields.add(option.getValue().toLowerCase());
    }
}

}

3
  • You need to edit your original post and include the controller code, especially the portions that define selectedRecords and selectedFields Feb 27 '19 at 0:04
  • Hi David I added my controller code.Please share some thoughts.
    – Suresh
    Feb 27 '19 at 5:30
  • @Suresh did you ever resolve this? I'm facing the exact same issue Jul 9 '19 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.