3

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

public Map<String, Schema.SObjectField> fieldMap{get;set;} 
fieldMap=Schema.sObjectType.Lead.fields.getMap();

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 ?

  • To get the best answer, please explain what goal your are trying to accomplish. As it is now, your example doesn't really make sense to me. – Guy Jun 27 '14 at 9:56
  • 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. – Salesforce Steps Jun 27 '14 at 10:03
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();
                    fieldMap=M;
1

Here's an example including a VF page where you can select the objects from a picklist:

http://www.cloudforce4u.com/2013/10/get-all-fields-of-object-in-apex.html

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.