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
sahil dhatraksahil dhatrak 

I want to write an controller to search the text entered in my visual force page how should i do it

<apex:page controller="search_controller">

<apex:sectionHeader title="HomePage" subtitle="Search and History" description="Use this page to search and browse history"/>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
        <apex:outputLabel value="Enter Search Text "/>
        <apex:inputText />
     
       
</apex:pageBlockSectionItem>
</apex:pageBlockSection> 
       
<br>       <apex:commandButton value="Search"/> </br>
<br>       <apex:commandButton value="History"/> </br>

</apex:pageBlock>
</apex:form>
</apex:page>

this is the visualforce oage i created
sahil dhatraksahil dhatrak
i have to search the text on google and display the result ....i dont wanna search the objects
Arunkumar RArunkumar R
Do you want to show the result in the visualforce page itself or it will redirect to google page?
Vidhyasagaran MuralidharanVidhyasagaran Muralidharan
Consideration:
searching account record from account object
VF Page:
<apex:page controller="search_controller">
<apex:sectionHeader title="HomePage" subtitle="Search and History" description="Use this page to search and browse history"/>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:outputLabel value="Enter Search Text "/>
<apex:inputText value="{!seachname}"/>
</apex:pageBlockSection>
<apex:pageBlockSection value="{!L}"id="seachresult" var="i">
<apex:column value="{!i.ID}"/>
<apex:column value="{!i.Number}"/>
<apex:column value="{!i.name}"/>
<apex:column value="{!i.description}"/>
</apex:pageBlockSection>
<br><apex:commandButton value="Search" rerender="searchresult"/> </br>
<br><apex:commandButton value="History"/> </br>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
Public class search_controller{
Public String seachname{get;set;}
Public List<Account> L{get;set;}
Public search_controller()
{
L=New <account>();
}
Public void search()
{
Account L=[Select ID,Number,name,description from account where name:seachname LIMIT 1];
}
}
sahil dhatraksahil dhatrak
@Arunkumar RArunkumar R i want the page to redirect to google search results
and 2nd scenario where all the results are displayed on a visual force page
sunny522sunny522
Hi Sahil,
    Go through the example below.

   Apexclass:

public class SearchTextInVFPage{
    public ApexPage vflist {get;set;}
    public ApexPage vfpage {get;set;}
    public string searchstring {get;set;}
    public SearchTextInVFPage(){
        vfpage =new ApexPage();
    }
    public PageReference SearchText()
      {
        system.debug('&&&&&&&'+searchstring );
        vflist =[SELECT ApiVersion,ControllerKey,ControllerType,Description,isAvailableInTouch,IsConfirmationTokenRequired,Markup,MasterLabel,Name,NamespacePrefix from ApexPage where name=:'SearchTextInVFPage'];
        system.debug('................'+ vflist);
        string searchstring1=searchstring.toLowerCase();
        string searchstring2=searchstring.toUpperCase();
       // searchstring=searchstring.equalsIgnoreCase(searchstring);
        if(vflist.Markup.contains(searchstring)==true ||vflist.Markup.contains(searchstring1)==true ||vflist.Markup.contains(searchstring2)==true)
        {
            system.debug('search string present in visualforce page');
        }
        else
          system.debug('search string not there in visualforce page');
       
      
        return null;
      }
}

visualforce page :

<apex:page controller="SearchTextInVFPage">
  <apex:form >
     <apex:inputText value="{!searchstring}"/>
      <apex:commandButton value="Search" action="{!SearchText}"/>
      <br/>
           test
       </apex:form>
 
</apex:page>

run the vf page and check.You can modify as you like.
The content of vf page will be in Markup field.

if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.


sahil dhatraksahil dhatrak
it is giving me an error
List has no rows for assignment to SObject
Error is in expression '{!SearchText}' in component <apex:commandButton> in page vfpage_search

An unexpected error has occurred. Your development organization has been notified.
sunny522sunny522
Hi Sahil,
     Go through the example below..

<apex:page sidebar="false" showHeader="false">
<iframe src='http://www.google.com/custom' width="100%" height="100%"/>
</apex:page>

Note:IF page didnot load then on the top right there is a button.click it to allow script.

if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.