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
Uvais KomathUvais Komath 

Showing multiple objects in a list

Please clear following doubts :

(1) How do i make the values of a picklist as the list of all objects available in my org

(2) How do i enable searching in these objects?

For eg:- if i select accounts then i should be able to search for accounts specifying condition (or How do i retrieve details on objects using an SOQL on the selected object in picklist)

(3) How do i Make the search available on multiple objects

for eg:- If i select multiple values : like Account,Contacts and Leads

Then search result list should show all accounts,contacts and leads that meet search condition (Like a search of account,lead,contact that have name starting with "a")

 

Please guide me through the procedure

 

ManojjenaManojjena
Hi Uvias,
Here I have writen one blog which is almost similar to your requirment .Here you will getall objectin a pick list.

http://manojjena20.blogspot.in/2015/10/selecting-any-object-and-display-all.html (http://manojjena20.blogspot.in/2015/10/selecting-any-object-and-display-all.html)



 
Uvais KomathUvais Komath

Thank you manoj...

2 more doubts remain :

Once the object is selected how do i execute an soql query over it?

Also how do i enable search on multiple objects

ManojjenaManojjena
Hi Uvais,

Check below code it will help you to search selected object record .
 
<apex:page controller="Quetion1Controller">
    <apex:form >
        <apex:inputText value="{!selectedSobject}" />
        <apex:commandButton value="Search" action="{!doSearch}"/>
    </apex:form>
    <apex:pageBlock >
        <apex:pageblockTable value="{!lstQuery}" var="eachRecord">
            <apex:column value="{!eachRecord.id}"/>
            <apex:column value="{!eachRecord['Name']}"/>
        </apex:pageblockTable>
    </apex:pageBlock>
</apex:page>



Controller

public class Quetion1Controller {
   public string selectedSobject{get;set;}
   public List<Sobject> lstQuery{get;set;}
     public Quetion1Controller(){
        lstQuery=new List<Sobject>();
    }
   public Void doSearch(){
        string Query='';
        Query='SELECT id,Name FROM '+ selectedSobject;
        lstQuery=Database.query(Query);
    }
}
For your second option you need to use SOSL for that you need enter a key word in text field and use sosl to finf matching reords
Check below link for SOSL it wil help !!
http://www.sfdcpoint.com/salesforce/sosl-example-in-salesforce/http://www.sfdcpoint.com/salesforce/sosl-example-in-salesforce
Let me know if it helps !!
Thanks
Manoj
Uvais KomathUvais Komath
I will work on it and provide feedback..Thanks a lot for the help
Uvais KomathUvais Komath

Doesnt seem to work for my use case.
Problem i face is :

I need a controller,
But what type of controller i need depends on the value selected from a picklist that shows all available objects in my org.

SO basically i want to know how to write a generic controller that handles search on multiple objects