function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
EPSWDEVEPSWDEV 

Dynamic Visual Force Page with details of different custom object.

Hi, I am trying to create a Visual source page which as two sections - Sec1 and Sec2. Sec1 display's the detail of lets say CustomObj1.
CustomObj1.field1 is a picklist  of different custom objects and depending on the value chosen, I want  the second section to display details of custom object chosen. for eg is Accounts was chosen display account detail feilds, if contact then contact detail.

whats the best way to do this?

I am implementing a component for sec2 that takes in the custom object type selected then dispaying the detail for that object however i find that I cannot specify object to a <apex:detail> tag. what are my options here.

thanks,


Sam.arjSam.arj
Using $Action you can get the View or Edit URL of an object (standard or custom) and then redirect the user to the standard detail layout of that object.

however, in order to do so you will need an object Id as well. Unless you are redirecting the user to object's detail page for creating a new record (Action.New).

Check the below link for more information:
http://salesforcesource.blogspot.com/2008/12/urlfor-function-finally-explained.html

http://salesforcesource.blogspot.com/2008/12/urlfor-function-finally-explained.html




Message Edited by Sam.arj on 01-06-2009 09:57 AM
EPSWDEVEPSWDEV
Sam,

I cannot redirect the user to a different page. The functionality intended is to show all the relevant details on the same page and when the user hits save I will be saving data to respective objects.

thanks,
Ron HessRon Hess
you could use rendered = false to hide the detail tags that you don't want to show

So, you can do this

Code:
<apex:detail subject="{!bang}" relatedlist="false" rendered="{!showBang}" />
<apex:detail subject="{!bang2}" relatedlist="false" rendered="{!showBang2}" />

 
then, both details will show up, unless you hide one or more with showBang* == false
EPSWDEVEPSWDEV
Hi Ron,

Not sure if I can do that, I should have mentioned in the initial post that CustomObj.Field1 is a textfield that just contains the name of custom object type . eg CustomObj.Field1 = MyCustomObj1__c.

What I am looking for is a way to create a object of type --> MyCustomObj1__c at runtime and then display the field. My biggest challenge right now is I cant event create a object that way.

Code:
sObject someObject = new sObject(CustomObj1.Field1)

 
the above code gives me error. is it even possible to create objects based on their name at run time ?? thanks this is much appreciated.

Ron HessRon Hess
you can access fields at runtime in a controller, using dynamic Apex , see docs for examples

you start by making a call like this :
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe(); 
and then loop over the keys until you find one that matches your string, then you have the Schema.SObjectType you need to perform a field describe.

i'm not sure you can bind a dynamic sobject field to a visualforce inputField , have not tried that.  You should be able to bind it to an inputText or Select list, but you may have to fetch the values using dynamic describe information.

details here:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_describe_objects_understanding.htm


Message Edited by Ron Hess on 01-06-2009 12:29 PM
dchasmandchasman
Please see this post for a discussion on this.
dchasmandchasman
Please see this post for a discussion on this last part.

Sam.arjSam.arj

Is sObjectType methods explained anywhere?

dchasmandchasman
Dynamic Apex support is well documented in the Apex Code dev guide here.


Message Edited by dchasman on 01-07-2009 09:31 AM