You need to sign in to do that
Don't have an account?
Retrieving Fields from Objects
I'm currently writing a Visualforce page that prompts the user to select an object in their org, and then choose a field from that object. I've found a way to compile the list of objects without any trouble, but I'm struggling to compile a list of the fields belonging to that object. When the user selects an object, I store the object name as a string. I can find the fields for a designated object using the code below:
Map<String, Schema.SobjectField> M = Schema.SObjectType.Account.fields.getMap(); List<Schema.SObjectField> resultList = M.values();
However, I can't seem to use that code to display the fields of every object. The object name goes where it says "Account" but when I try using the string name for the object that was selected, it throws me an error message. I can't find a way to reference any object without manually typing the name in. I know I need to either convert the string name to some other sort of data type or come up with a new algorithm altogether.
Does any one have any suggestions?
Hey Adam,
You're over thinking this.
All Answers
Hey Adam,
You're over thinking this.
I think this example might help you
http://forceschool.blogspot.com/2011/06/dynamic-binding-when-object-name-is.html
Thank you both for your responses. Both examples helped me very much.
Have you guys ever encountered this or if you have any solution for this, it would be really helpful.
Thanks in advance