0

I have list which consists of field name.

        fieldList = new List<String>(); 
    for(Schema.FieldSetMember memberObj : SObjectType.Account.FieldSets.rakch__DemoFieldSet.getFields()){
        qwerty += ','+memberObj.getFieldPath();
        fieldList.add(memberObj.getFieldPath());
    }

    readOnlyFields   = new List<SObjectField>();
    accessableFields = new List<SObjectField>();
    for(SObjectField field :sObjectType.Account.fields.getMap().values()){
        if(field.getDescribe().isAccessible() && !field.getDescribe().isUpdateable() && !field.getDescribe().isCreateable()){
            readOnlyFields.add(field);
            nonEditableFields += ','+field ;
        }else{
            accessableFields.add(field);
            editableFields += ','+field ;
        }
    }
    
    editable = new List<String>();
    editable = editableFields.split(',');

Here editable is a list,

and I have an sObject type Account selectedList3 ans SelectedList4.

<apex:repeat value="{!editable}" var="a">
            <tr>
                <td><b>{!a}</b></td>
                <td>{!SelectedList3[a]}</td> **===> ERROR**
                <td>{!SelectedList4[a]}</td> **===> ERROR**
            </tr>
        </apex:repeat>

can someone help me with this.

Error: Exception: Invalid field for SObject Account Error is in expression '{!selectedList3[a]}' in component apex:repeat in page rakch:mergeaccountsvfpage Error evaluating dynamic reference ''

Thank you.

1 Answer 1

2

When you split the list, there's an empty element at the end. This is because you're building a string like:

,Field1,Field2,Field3,Field4...

You shouldn't ever do this to begin with. It would have been so much easier to:

editable = new String[0];
nonEditable = new String[0];
for(SObjectField field :sObjectType.Account.fields.getMap().values()){
  if(field.getDescribe().isAccessible() && !field.getDescribe().isUpdateable() && !field.getDescribe().isCreateable()){
      readOnlyFields.add(field);
      nonEditable.add(field);
    }else{
      accessableFields.add(field);
      editable.add(field);
    }
}
editableFields = String.join(editable,',');
nonEditableFields = String.join(nonEditable,',');

Using String.join is easier to use and always ensures that you don't have a trailing or leading comma when creating a string from a list of elements.

You must log in to answer this question.

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