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
Champ123Champ123 

Display results of unknown SOQL query

Hi all,

 

I have a requirement that I'd like to know if it is possible. I have visualforce page which will display the results of a SOQL query, however the SOQL query is dynamic and could be a query on Custom Objects or Standard Obejcts. I'm currently hard coding a SOQL query into the controller class whilst trying to figure out how it will work. I intend to display the results of the SOQL query in a pageBlockTable or dataTable in the Apex.

 

Is this possible in Salesforce, if so could anyone give me an example of how it would work both in Visualforce and Apex?

 

Thanks in advance.

Cory CowgillCory Cowgill

Yes you can do this using several mechanisms.

 

Dynamic SOQL - You can use Dynamic SOQL to build your SOQL queries at run time:

http://corycowgill.blogspot.com/2011/01/building-dynamic-soql-select-all-query.html

 

You can use Field Sets to display the results dynamically in your VF Page.

https://github.com/corycowgill/DynamicSOQLWithVisualforceComponents

ShahTheTrainerShahTheTrainer

please go through the link to see the demo.

 

https://shahthetrainer-developer-edition.ap1.force.com/SearchBox_Table_DetailedList

 

https://shahthetrainer-developer-edition.ap1.force.com    for other demos

 

I can share you the code sample, if you are looking for this