0

Im trying to get editable fields and non editable fields and use them to iterate in visualforce using apex:repeat.

Apex:code

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 + ',';
        }
    }

Vf Code:

<apex:repeat value="{!accessableFields}" var="a">
<tr><td>{!selectedList1.[a]}</td></tr>
</apex:repeat>

selectedList1 is an account type which contains account information.

can some one hep me to avoid this error. Error: Invalid field for SObject Account

Thank you.

1 Answer 1

0

Will this work?

List<String> accessableFields = new List<String>();
String nonEditableFields = '';
String editableFields = '';

for(SObjectField field :SObjectType.Account.fields.getMap().values()){
    if(field.getDescribe().isAccessible() && !field.getDescribe().isUpdateable() && !field.getDescribe().isCreateable()){
        readOnlyFields.add(field.getDescribe().name);
        nonEditableFields += field.getDescribe().name + ',';
    }else{
        accessableFields.add(field.getDescribe().name);
        editableFields += field.getDescribe().name + ',';
    }
}

System.debug(readOnlyFields);
System.debug(accessableFields);
System.debug(nonEditableFields);
System.debug(editableFields);

Bascically returning List<String> instead of List<SObjectField>?

2
  • Now im trying to display list of accessible feilds using apex:repeat <apex:repeat value="{!accessableFields}" var="a"> <tr><td>{!selectedList1[a]}</td></tr> </apex:repeat> Im facing an error : Incorrect parameter type for subscript. Expected Text, received FieldToken
    – Ram
    Nov 6, 2020 at 17:20
  • Hi @Ram I was misled (should have re-read). I was primarily looking at the way you tried to create the nonEditableFields and editableFields strings. But indeed in order to dynamically bind within the VF page you need to have readOnlyFields and accessibleFields as a List<SObjectField>. Can you try to use: <td><td><apex:outputField value="{!selectedList1[a]}"/></td></tr>
    – Jeronimo
    Nov 9, 2020 at 14:09

You must log in to answer this question.

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