1

I used apex:repeat and apex:datalist to display all the fields from the map. I am able to display only the values in the map not the key value from the map. Can anyone here can help me out what is the issue. VF :

  <apex:dataList value="{!sObjectFieldMap}" var="sobj">
        {!sobj}
        {!sObjectFieldMap[sobj]}
    </apex:dataList>

controller :

public with sharing class survey_ResultV2Ctrl{
public Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
public Map<SObject, List<Schema.SObjectField>> sObjectFieldMap {get; set;}
public List<Schema.SObjectField> sObjectFieldLst = new List<Schema.SObjectField>();
public List<wrapperClass> wcls {get; set;}
public set<Schema.SObjectType> objNameSet =  new set<Schema.SObjectType>();
public Schema.SObjectType sobjtyp;
public survey_ResultV2Ctrl(){
    sObjectFieldMap = new  Map<SObject, List<Schema.SObjectField>>();
    wcls =  new List<wrapperClass>();
    survey_ResultDisplay();
}

public void survey_ResultDisplay(){

    for(Filter_Field_Set__c ffs : [SELECT Name, Field_Set_Category__c, Object_Fields__c, Object_Fields_Name__c FROM Filter_Field_Set__c Where Field_Set_Category__c = 'a0F9000000R5Fau']){
        system.debug('All the result from Filter Field Set object ' + ffs.Name);
        system.debug('Schema Map contains Key as object name ' + schemaMap.containsKey(ffs.Name));
        Map <String, Schema.SObjectField> fieldMap = schemaMap.get(ffs.Name).getDescribe().fields.getMap();
        if(schemaMap.containsKey(ffs.Name)){
            system.debug('Schema object Values ' + schemaMap.get(ffs.Name));
            system.debug('All the fields related to Schema object ' + fieldMap.get(ffs.Object_Fields_Name__c));

            if(sObjectFieldMap.containskey(schemaMap.get(ffs.Name).newSObject())){
                sObjectFieldLst.add(fieldMap.get(ffs.Object_Fields_Name__c));
                //sobjtyp = schemaMap.get(ffs.Name);
                sObjectFieldMap.put(schemaMap.get(ffs.Name).newSObject(), sObjectFieldLst.clone());
                //objNameSet.add(schemaMap.get(ffs.Name));
                //wcls.add(new wrapperClass(schemaMap.get(ffs.Name), sObjectFieldLst));
                sObjectFieldLst.clear();
            }
            else{
                sObjectFieldLst.add(fieldMap.get(ffs.Object_Fields_Name__c));

                sObjectFieldMap.put(schemaMap.get(ffs.Name).newSObject(), sObjectFieldLst.clone());
                //wcls.add(new wrapperClass(schemaMap.get(ffs.Name), sObjectFieldLst));
                //objNameSet.add(schemaMap.get(ffs.Name));
            }
        }

    }


    system.debug('The wapper class after loop ' + wcls);
    system.debug('The Map after loop ' + sObjectFieldMap);

}


public with sharing class wrapperClass{

    public list<Schema.SObjectField> fieldname {get; set;}
    public Schema.SObjectType objectName {get; set;}

    public wrapperClass(Schema.SObjectType objectName, list<Schema.SObjectField> fieldname){
         objectName = objectName;
         fieldname = fieldname;
    }
}   
}

please help me get the solution.

  • Complex type can not be part of MAP key if iterating, well explained by crmprogdev – Ashwani Sep 28 '14 at 16:37
1

I'm not certain how you're using this class, but the key in your wrapper class is the sObject or Schema.SObjectType objectName. Are you wanting to display objectName as part of your field list? I ask because I don't see where you're trying to display records. I'm assuming {!sobj} isn't displaying. If that's the case, you may need to do an <apex outputtext> for each {!sobj} to get it to display the sObjectType or objectName.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.