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
niharnihar 

create a visual force page to fetch all records ids in the org

Hi all,
My requirment is to create a visual force page (apex class) in that an id field and search button should be inserted........
when i paste an record id   in the   id field of visualforce page record should be displayed and related lists should be also displayed
Best Answer chosen by nihar
Narender Singh(Nads)Narender Singh(Nads)

Hi Nihar,
There are two ways to approach this problem. I will share the simpler one with you, because the other one is too complex to explain for me.

You can start by making a visual force page with a custom controller. Your VF page will include two main things: 
1. An input type field where you will enter the ID to search.
2. A button to call search function.

And your custom controller code will look something like this:

public class pagecontroller{
  
  public string inputID{get;set;}
  
  public pagereference search(){
       PageReference pageRef = new PageReference('/'+inputID);
       return pageRef; //This will redirect you to the standard record page of that record
  }
}

Let me know if it helps.
Thanks!

All Answers

Narender Singh(Nads)Narender Singh(Nads)

Hi Nihar,
There are two ways to approach this problem. I will share the simpler one with you, because the other one is too complex to explain for me.

You can start by making a visual force page with a custom controller. Your VF page will include two main things: 
1. An input type field where you will enter the ID to search.
2. A button to call search function.

And your custom controller code will look something like this:

public class pagecontroller{
  
  public string inputID{get;set;}
  
  public pagereference search(){
       PageReference pageRef = new PageReference('/'+inputID);
       return pageRef; //This will redirect you to the standard record page of that record
  }
}

Let me know if it helps.
Thanks!

This was selected as the best answer
Afghan Khair.Afghan Khair.
public with sharing class pagecontroller { 
public list <account> acc {get;set;} 
public string searchstring {get;set;} 
public pagecontroller( ) { 

public void search(){ 
string searchquery='select name,id from account where name like \'%'+searchstring+'%\' Limit 20'; 
acc= Database.query(searchquery); 

public void clear(){ 
acc.clear(); 

}

<apex:page Controller="pagecontroller" > 
<apex:form > 
<apex:inputText value="{!searchstring}" label="Input"/> 
<apex:commandButton value="Search" action="{!search}"/> 
<apex:commandButton value="Clear" action="{!clear}"/> 
<apex:pageBlock title="Search Result"> 
<apex:pageblockTable value="{!acc}" var="a"> 
<apex:column value="{!a.name}"/> 
<apex:column value="{!a.id}"/> 
</apex:pageBlockTable> 
</apex:pageBlock> 
</apex:form> 
</apex:page>
niharnihar
hi Narender Singh(Nads),
thankyou for the code ..you said there are 2 ways of approach......can you sen me the 2nd way of approach
Narender Singh(Nads)Narender Singh(Nads)
Hi Nihar,
The second apporach will require you to first find the sobject type from the provided record ID and then do do a SQOL query for that ID for its object type. And then you can display your data on your VF anyhow you like.
niharnihar
hi narender,
Actually my task is there are 6 objects obj1,obj2,obj3,obj4,obj5,obj6
in which obj1 has realtion with obj2 & obj2 has realtion with obj3
& obj3 has realtion with obj4 & obj4 has realtion with obj5 & obj5 has realtion with obj6
but when i paste an record id in the search box i must get the related lists of all 6objects in one page..............
Narender Singh(Nads)Narender Singh(Nads)
Hi Nihar,
Tell me this, when the user enters the record ID of any record that belongs to one of the 6 objects you mentioned, you want the related Records of all 6 objects or only the records of those objects which lie in the lower hierarchy?
niharnihar
hi narender,
I want the related Records of all 6 objects...................................