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
krishna casukhela 7krishna casukhela 7 

searching value

Hello friends
I have 1 lakh records in account object.
I am using an apex class and I want to search for a particular account name .
How can I perform this search likewise I cannot use  [select Name​​ from account limit 50000] because what happens if the account name is after the limit value.

I do not want to use batch apex , only apex class
I hope I am clear.

Kindly let me know

Thanks
krishna​​
 
Akhil AnilAkhil Anil

As long as you are not fetching more than 50000 records you should not hit the limit. Since you are seraching only for a particular Account Name, you can go ahead without a batch apex, If you are sure that you there aren't more than 50000 records with the same name.
RAM AnisettiRAM Anisetti
try this one...
 
<apex:page standardController="account" extensions="ramsearchcontroller">  
  <apex:form >  
 <apex:inputText value="{!searchstring}" label="Input"/>   
  <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>   
  </apex:form>  
 </apex:page>

=============================================

public with sharing class ramsearchcontroller {  
   public list <account> acc {get;set;}  
   public string searchstring {get;set;}  
   public ramsearchcontroller(ApexPages.StandardController controller) {  
   }  
   public void search(){  
     string searchquery='select name,id from account where name like \'%'+String.escapeSingleQuotes(searchstring)+'%\' ';  
     acc= Database.query(searchquery);  
   }  
   public void clear(){  
   acc.clear();  
   }  
 }

 
krishna casukhela 7krishna casukhela 7
Hi Ram
will ur code work even if there are 2 lakh records:?​

I have put my code here for ur ereference . Please let me know if SOQL query impacts performance if there are 1 lakh / 2 laksh records or more.​

<apex:page standardController="Account"
            extensions="MySOSLSearch"
            tabStyle="Account">
           
<apex:form >
  <apex:inputText value="{!SearchString}"/>
  <apex:commandButton action="{!Search}"
                       value="SearchAccount"/>
  <apex:pageBlock mode="DisplayAccount Info">
 
     <apex:pageBlockTable value="{!accts}"
                          var="a">
    
         <apex:column value="{!a.Name}"/>
         <apex:column value="{!a.Type}"/>
         <apex:column value="{!a.Industry}"/>
     </apex:pageBlockTable>
 
  </apex:pageBlock>
</apex:form>
 </apex:page>

public class MySOSLSearch
{
    public String SearchString{get;set;}
   
    public list<Account> accts;
   
    public MySOSLSearch(ApexPages.StandardController controller)
    {
    }
   
    public list<Account> getaccts()
    {
          return accts;  
    }
   
    public PageReference Search()
    {
          list<list<Account>> lstr = [FIND : SearchString IN ALL FIELDS RETURNING Account(Name, Type, Industry)];
          accts =(list<account>)lstr[0];  //for single record
          return null;
    }
}

Please let me know performance of above code .

thanks
sonali​​
Jairaj SinghJairaj Singh
Not sure why you are worried about the APEX limit over here, If you are searching a particular account then you should be good.