I'm using Schema to retreive the fields and put them in a map that I can use in my Visualforce page.

public Map<String,String> m1{get;set;}
public List<String> fieldsList {get; set;} 

Schema.DescribeSObjectResult oppDescribe = T1_Passif__c.sObjectType.getDescribe();
Map<String, Schema.SObjectField> fields = oppDescribe.fields.getMap();
                for (Schema.SObjectField field: fields.values())
                    Schema.DescribeFieldResult dr = field.getDescribe();
//add their labels to a list to maintain an order
FieldsList.add('Capital social ou personnel (1)');
FieldsList.add('Moins: actionnaires'); 


<apex:pageBlockTable value="{!fieldsList}" var="dirKey">
        <apex:column >

                <apex:outputText value="{!dirKey}" />
            <apex:facet name="header"><div align="center"> PASSIF </div></apex:facet>
        <apex:column style="text-align:center">
            <apex:outputText value="{!m1[dirKey]}"/>
            <apex:facet name="header" > <div align="center"> Exercice </div> </apex:facet>


And I get the following error even if the field I'm trying to access exist in the object custom fields and should exist in the map.

the only solution is to manually add:

FieldsList.add('Total des capitaux propres (A)');
                     m1.put('Total des capitaux propres (A)','');
                     m1.put('Total des capitaux propres (A)',String.valueOf(obj.Total_des_capitaux_propres_A__c));

1 Answer 1


Typically you should use the API Name as the map key because it is unique. Also if you want to ensure that you get an exact match, it is probably best to use field describes.


Even a simple case mismatch or trailing whitespace could cause your manual additions to fail, and if those labels change then poof, your code breaks again.

In your VisualForce, you can still render the label using the API Name:

  • But in my table I want to display the label and value by using the key and the value of the map, that's why I chose getLabel() instead of getName()
    – Yousra
    Commented May 6, 2015 at 14:13
  • 1
    Again, it is not a unique key and is a bad idea to use as your map key. You can still retrieve the label, I modified my answer to show how.
    – Adrian Larson
    Commented May 6, 2015 at 14:16
  • Deos sObjectType.getDescribe().fields.getMap() get every single field for that object ? It seems to me like it is not getting lookups and formula fields. Is that correct ? @AdrianLarson
    – MadMax
    Commented Jun 4, 2019 at 23:29
  • Incorrect. It gets every field.
    – Adrian Larson
    Commented Jun 5, 2019 at 0:27

You must log in to answer this question.

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