can anyone help me to display all the standard objects in one picklist and when i select any one object, then all the records in that objects have to display.
public class ClassName{
public List<SelectOption> objects {get; set;}
public List<SObject> records {get; set;}
public string choosenObject {get; set;}
public ClassName(){
objects = new List<SelectOption>();
records = new List<SObject>();
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
List<String> objectList = new List<String>();
objectList.addAll(gd.keyset());
Schema.DescribeSobjectResult[] results = Schema.describeSObjects(objectList );
for(Schema.DescribeSobjectResult res : results) {
if( ! res.isCustom())
objects.add(new selectOption(res.getName() ,res.getLabel()));
}
}
public void queryMe(){
if(string.isNotBlank(choosenObject))
records = database.query('select Id, Name from '+choosenObject);
//you may need to remove Name field for some objects
}
}
I am getting till displaying all the records of all objects in one page, but i want to display like if i click on Account in picklist then particular object records should to be display and same for all other standard objects. can you help me for this.
public class ClassName{
public List<SelectOption> objects {get; set;}
public List<SObject> records {get; set;}
public string choosenObject {get; set;}
public ClassName(){
objects = new List<SelectOption>();
records = new List<SObject>();
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
List<String> objectList = new List<String>(); objectList.addAll(gd.keyset());
Schema.DescribeSobjectResult[] results = Schema.describeSObjects(objectList );
for(Schema.DescribeSobjectResult res : results) {
if( ! res.isCustom())
objects.add(new selectOption(res.getName() ,res. getLabel());
}
}
public void queryMe(){
if(string.isNotBlank(choosenObject)
records = database.query('select Id, Name from '+choosenObject);
//you may need to remove Name field for some objects
}
}
For me no need to go to list view page of any objects. I wants to get all the records from standard objects and to display it in one page and I did upto it.
I dont know how to display the records for particular selected objects in picklist.
I have given the same in the above comment, but it will only dispaly record ids of the selected object and even if you query other fields you can't manage it as a table
public class ClassName{
public List<SelectOption> objects {get; set;}
public List<SObject> records {get; set;}
public string choosenObject {get; set;}
public ClassName(){
objects = new List<SelectOption>();
records = new List<SObject>();
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
List<String> objectList = new List<String>();
objectList.addAll(gd.keyset());
Schema.DescribeSobjectResult[] results = Schema.describeSObjects(objectList );
for(Schema.DescribeSobjectResult res : results) {
if( ! res.isCustom())
objects.add(new selectOption(res.getName() ,res.getLabel()));
}
}
public void queryMe(){
if(string.isNotBlank(choosenObject))
records = database.query('select Id, Name from '+choosenObject);
//you may need to remove Name field for some objects
}
}
Yes, we can display other fields as well, I can't provide you the solution as it takes a lot of time, but I can provide you the way to solve it
for that you need to select which fields you want to query and use a wrapper to hold the state of selected fields use dynamic table coulmns that will render based on fields selected
You can get fields of the selected fields by using schema classes 'ObjectName.SobjectType.getDescribe().getFields()' like this.
Thanks Choose it as best answer if you found my answer helpful
public class SobjectList{ public string val {get;set;} public string obj{get;set;} public String AccountList { get; set; } //Subclass : Wrapper Class public class Accountwrap { //Static Variables public string id; public string name; public string Phone; //Wrapper Class Controller Accountwrap() { Phone = ''; } } //Method to bring the list of Account and Serialize Wrapper Object as JSON public static String getlstAccount() { List < Accountwrap > lstwrap = new List < Accountwrap > (); List < account > lstacc = [SELECT Id, Name, Phone FROM Account]; for (Account a: lstacc) { Accountwrap awrap = new Accountwrap(); awrap.id = a.id; awrap.name = a.name; if (a.Phone != null) { awrap.Phone = a.Phone; } lstwrap.add(awrap); } return JSON.serialize(lstwrap); } }
can u do the modification of using schema class in it.
All Answers
use this select option to generate picklist in visual force page and use dynamic query to return results
Thank you
Choose it as best answer if it has helped you
You can use below code for displaying only standard objects in a picklist.
Best Regards,
Mithun.
Hi,
Thanks for your support.
I am getting till displaying all the records of all objects in one page, but i want to display like if i click on Account in picklist then particular object records should to be display and same for all other standard objects.
can you help me for this.
Thanks,
Sushma.
You can use below code
Best Regards,
Mithun.
My requirement is if i select object in picklist, then i have to display the records.
The apex class as follows
and the Vf page
You need to accept that every object has different set of coulmns and data types, so you may need use links to go to corresponding object links
like for Account '/001 ' and contact '/003' etc
Thanks
Choose it as best answer if it has helped you
For me no need to go to list view page of any objects. I wants to get all the records from standard objects and to display it in one page and I did upto it.
I dont know how to display the records for particular selected objects in picklist.
Thanks for your support.
Have you tried the above code?
Is there any other way to display the other fields also.
for that you need to select which fields you want to query and use a wrapper to hold the state of selected fields
use dynamic table coulmns that will render based on fields selected
You can get fields of the selected fields by using schema classes 'ObjectName.SobjectType.getDescribe().getFields()' like this.
Thanks
Choose it as best answer if you found my answer helpful
Apex class:
public class SobjectList{
public string val {get;set;}
public string obj{get;set;}
public String AccountList { get; set; }
//Subclass : Wrapper Class
public class Accountwrap {
//Static Variables
public string id;
public string name;
public string Phone;
//Wrapper Class Controller
Accountwrap() {
Phone = '';
}
}
//Method to bring the list of Account and Serialize Wrapper Object as JSON
public static String getlstAccount() {
List < Accountwrap > lstwrap = new List < Accountwrap > ();
List < account > lstacc = [SELECT Id, Name, Phone
FROM Account];
for (Account a: lstacc) {
Accountwrap awrap = new Accountwrap();
awrap.id = a.id;
awrap.name = a.name;
if (a.Phone != null) {
awrap.Phone = a.Phone;
}
lstwrap.add(awrap);
}
return JSON.serialize(lstwrap);
}
}
can u do the modification of using schema class in it.
Thanks.