+ Start a Discussion
vandana rajuvandana raju 

search for a value in 2 million records

I am trying to understand how to go about below issue.
I have 2 million historical records in account object.
I have as follows:
public class somecontroller
    public String searchstring{get;set;}
    public list<Account> acc{get;set;}
    public somecontroller(ApexPages.StandardController controller) {}
    public PageReference Search()
      string searchquery='select ID,Name from Account where name like \'%'+String.escapeSingleQuotes(searchstring)+'%\' ';   

      acc= Database.query(searchquery);   

      return null;
<apex:page standardController="Account"
     <apex:inputText value="{!SearchString}"
                                  label="Enter Account Name"/>
     <apex:commandButton value="Search records" action="{!search}"/>  
     <apex:commandButton value="Clear records" action="{!search}"/>  
       <apex:pageBlock title="Search Result">  

     <apex:pageblockTable value="{!acc}" 
     <apex:outputlink value="/{!a.id}">{!a.Name}</apex:outputlink>  
     <apex:column value="{!a.id}"/>  



If the number of rows is less than or equal to 50000 then its fine but if number of rows is more than 50000 then I will have to use a batch apex.
Now assuming 1 lakh rows are returned then how can I hold this result information in batch apex?
I may want to show these records in a PDF or excel.

I really hope I am very clear.
Please let me know.