You need to sign in to do that
Don't have an account?
Leuwend Job Hapa
Is it possible to display records in a datatable with the queried columns dynamically.
Assuming that we have a list of Account objects from the database:
List<Account> listOfAccounts = new List<Account>(); for (Account a : [SELECT Id, Name, Type FROM Account LIMIT 10]) { listOfAccounts.add(a); }I want to display it on a datatable that automatically adds the columns that I have queried (ID, Name, and Type).
-
Retreive field names from your query result and store them in a separate array
-
Create a List<List<String>> collection and in the first row, store your field-names, and in subsequent rows, store values from your sObject list.
-
Display this List<List<String>> collection in your VF page in a table.
Here is some code that has been taken from an article that talks about how to retrieve field names, basicaly, this converts the query-result to jSON and parses it to get field-names, you can use the same code to retreive field-values as well. Article URL: http://salesforce.stackexchange.com/questions/24336/how-do-i-get-the-list-of-fields-of-sobjectAll Answers
-
Retreive field names from your query result and store them in a separate array
-
Create a List<List<String>> collection and in the first row, store your field-names, and in subsequent rows, store values from your sObject list.
-
Display this List<List<String>> collection in your VF page in a table.
Here is some code that has been taken from an article that talks about how to retrieve field names, basicaly, this converts the query-result to jSON and parses it to get field-names, you can use the same code to retreive field-values as well. Article URL: http://salesforce.stackexchange.com/questions/24336/how-do-i-get-the-list-of-fields-of-sobjectyou can refer below link:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_dataTable.htm
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal