I am trying to get describe information about an sObject similar to this:

public Map<String, Schema.SObjectField> fieldMap{get;set;} 

However, I want to substitute my own String variable "Field" instead of "LEAD" which is Standard object name.

myString='Schema.sObjectType.' + Field+ '.fields.getMap();';       
fieldMap = myString;   

Error Message : : Illegal assignment from String to MAP<String,Schema.SObjectField>

So Is there any Conversion Method for String to Map ? Or Any Suggestions where I can easily assign myString in fieldMap ?

  • I am trying to get List of all the fields in selected Object, where I have got API name of selected object in the "Field" variable. so by putting that in Map I am adding its fields in table below this code. Commented Jun 27, 2014 at 10:03

1 Answer 1


I think this should work

  Map<String,Schema.SObjectType> gd = Schema.getGlobalDescribe();
                    Schema.SObjectType sobjType = gd.get(Field);
                    Schema.DescribeSObjectResult r = sobjType.getDescribe();
                    Map<String,Schema.SObjectField> M = r.fields.getMap();

You must log in to answer this question.

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