I am getting all objects and fields now I need to add the object and field to a map where map is
public List sObjectFieldLst = new List();
How can add the values to the map from Schema.SObjectType When I tried to add I am getting an error :
Error: Compile Error: Incompatible key type Schema.SObjectType for
MAP<SObject,LIST<Schema.SObjectField>>
My code :
public class survey_ResultV2Ctrl{
public Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
public Map<SObject, List<Schema.SObjectField>> sObjectFieldMap = new Map<SObject, List<Schema.SObjectField>>();
public List<Schema.SObjectField> sObjectFieldLst = new List<Schema.SObjectField>();
public survey_ResultV2Ctrl(){
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 = 'a0F9000000R5FZr']){
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));
sObjectFieldLst.add(fieldMap.get(ffs.Object_Fields_Name__c));
sObjectFieldMap.put(schemaMap.get(ffs.Name), sObjectFieldLst);
}
}
}
}
The object and field names are saved in a object called Filter_Field_Set__c. Please help me out to get the solution on this issue.
public Map<Schema.SObjectType, List<Schema.SObjectField>> sObjectFieldMap = new Map<Schema.SObjectType, List<Schema.SObjectField>>();
That will give you a mapping of each type to a list of fields for that type. If you want a mapping from an instance of an object to a list of it's fields, usesObjectFieldMap.put(schemaMap.get(ffs.Name).newSObject(), sObjectFieldLst);
when adding to the map.