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
vandana rajuvandana raju 

search for a value in 2 million records

Hi
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"
           extensions="SomeController">
<apex:form>
     <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}" 
                          var="a">  
     <apex:column>  
     <apex:outputlink value="/{!a.id}">{!a.Name}</apex:outputlink>  
 
     </apex:column>  
 
     <apex:column value="{!a.id}"/>  

    </apex:pageBlockTable>     

   </apex:pageBlock>

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.