+ Start a Discussion
BZKBZK 

Dynamic access to $ObjectType

Is it possible to access $ObjectType dynamically, e.g. $ObjectType['Lead'] or $ObjectType['Custom_Object__c'].

That syntax clearly doesn't work, but I'm looking for something that lets me build a visualforce interface without necessarily knowing what object I'm working with.

 

I know I can write custom controller logic to handle the describe calls, but if this is possible, it would make the code cleaner and more easy to maintain.

Shashikant SharmaShashikant Sharma

I just posted this on my blog 5 minutes ago. It seems as if I posted it for you. See my blog

 

Dynamic Binding When Object Name is also dynamic

 

http://forceschool.blogspot.com/2011/06/dynamic-binding-when-object-name-is.html

 

I have used 'Account' in this line in apex controller

 

 

Schema.sObjectType sObjType = globalDescription.get('Account'); 

 

 

you can take this from query string also to fulfil your requirement.

BZKBZK

That's an elegant solution, but i explicitly said that I was asking about using the $ObjectType global variable in Visualforce, and <i>not</i> about writing custom controller logic; I know how to do that already.

 

The answer to my question may be 'no'.

Shashikant SharmaShashikant Sharma

I don't think there is any such way then in VFP, I will reaserch about it and will let you know.

jkucerajkucera

There's a new VF feature called dynamic binding that may let you do what you want.  It lets you do things like make a multi-object list view where the user selects the object, clicks a button, and then a table of data from that object is populated in a list controller.

 

Is that along the lines of what you're looking to do?