You need to sign in to do that
Don't have an account?
Visualforce Page with dynamic standardcontroller
Hello all
lets take this for example for a vf page
apex:page standardController="Contact" extensions="vf_ContactsUpdateFieldSetsController" showHeader="false" sidebar="false"
I want to be able to set the standartController with a changing value so this page would be dynamic and serve various objects.... and not just Contact
I also need to be able to use : contact = (Contact)controller.getRecord(); ----------> in a dynamic way so I can still can get the values from the screen
is there a way to achive that ? maybe by using only the extensions ? but how can I get the values of the fields in the screen ?
Any help or direction would be appriciated
background behind that need:
I would like to display a fieldset on that page , but the fieldset can be once from Contact , or any other Object.
TIA
You just need a controller and VFP.
1) In controller when you get the id of record you need to dyanamiclly find the object by the first three digit of id ( because first three digit is the keyprefix of object so you can find object by id )
2) After getting object you need to store the object record in sObject type.
3) For fields you need call describe call on object and there is a method in describecall by which you can get the all fieds of that object.
4) Store the field result in list and make a dyanamic query and use Database.query method to fetch the record and save in sobject type.
5) Use get method on sobject and pass the value of field which you get from descrobe call and iterate and pass value in get method to get the value of tha field form sobject.
http://www.salesforce.com/us/developer/docs/dbcom_apex250/Content/apex_methods_system_sobject_describe.htm
http://salesforcenow.blogspot.in/2012/08/salesforce-find-object-from-record-id.html
All Answers
Thanks.... any other workarounds any one might think of ?
You just need a controller and VFP.
1) In controller when you get the id of record you need to dyanamiclly find the object by the first three digit of id ( because first three digit is the keyprefix of object so you can find object by id )
2) After getting object you need to store the object record in sObject type.
3) For fields you need call describe call on object and there is a method in describecall by which you can get the all fieds of that object.
4) Store the field result in list and make a dyanamic query and use Database.query method to fetch the record and save in sobject type.
5) Use get method on sobject and pass the value of field which you get from descrobe call and iterate and pass value in get method to get the value of tha field form sobject.
http://www.salesforce.com/us/developer/docs/dbcom_apex250/Content/apex_methods_system_sobject_describe.htm
http://salesforcenow.blogspot.in/2012/08/salesforce-find-object-from-record-id.html
Ashlekh Thank you very much for this...
Im starting to work on it ,
1) managed to find the objectName based on it's Id and all is ok
2) this I need some more explanation if you can
In which type should I store it and how ? and will it be the connection between the VF page and controller so I can get the values from the screen fields ?
if I understand correctly this should replace this line right ? : contact = (Contact)controller.getRecord();
regarding 3,4,5 I think I will manage but first I guess 2 should be more clear for me If you can please have a small example
TIA again
a little progress...
I have managed to create Sobject from a string with a name of an object which created and empy object.
The problem that I can't figure out is
1) how to get the value of the inputfield (in the VF Page) and get it's value in the controller...
when it was with standardController="Contact" for example
I had contact = (Contact)controller.getRecord();
and to get a value I used : contact.get('some field name api');
how can I do it now with Sobject ?
I have used VF page with with only controller attribute for the apex:page tag (no standardController)
according to the Id that passed to the controller I found The object Name , and than Instantiated it