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
MXMX 

Find all Instances of an Objects.

Hi guys,

 

I developed an Visualforce Page, which shows all Objects that are available. Now I want to find all Instances of one Particular Object. 

 

I tried some stuff like this, but can't verify if it works, cause i have no idea how i could get a String with the Name out of the SObject.

Do I need a wrapperclass for showing the Results in a table?

 

String queryString = 'SELECT Id, Name, FROM '+ paramFromVF; // paramFromVF is the name of the Object
List<sObject> L = Database.query(queryString);

 

Anyway, I think this is quite a beginner question, but as I am a beginner this is tough for me at the moment.

Thanks a lot for your help.

Best Answer chosen by Admin (Salesforce Developers) 
Bindhyachal Kumar SinghBindhyachal Kumar Singh

Hi MX,

 

I think you are trying to use Dynamic soql query.

 

//This is your code

 

String queryString = 'SELECT Id, Name, FROM '+ paramFromVF;  

 

Use following code:  

 

// Remove comma(,) after Name.

String queryString = 'SELECT Id, Name FROM '+ paramFromVF;  
List<sObject> instancelist = Database.query(queryString);

 

No, you don't need to use wrapperclass.

You can display results as a table on VF page using pageblocktable.

 

if this is the solution for your issues then please mark as a solution and it helps other for similar issues.

All Answers

Bindhyachal Kumar SinghBindhyachal Kumar Singh

Hi MX,

 

I think you are trying to use Dynamic soql query.

 

//This is your code

 

String queryString = 'SELECT Id, Name, FROM '+ paramFromVF;  

 

Use following code:  

 

// Remove comma(,) after Name.

String queryString = 'SELECT Id, Name FROM '+ paramFromVF;  
List<sObject> instancelist = Database.query(queryString);

 

No, you don't need to use wrapperclass.

You can display results as a table on VF page using pageblocktable.

 

if this is the solution for your issues then please mark as a solution and it helps other for similar issues.

This was selected as the best answer
MXMX

Thanks a lot, what a stupid mistake.