+ Start a Discussion

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:



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



please go through the link to see the demo.




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


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