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
Aman BishtAman Bisht 

Getting runtime exception in visualforce page

i am getting rutime exception in this code...
public with sharing class SearchTask {
Public String FirstName {Get;Set;}
Public String LastName {Get;Set;}
Public String Email {Get;Set;}
Public String Query;
    public Void Searchtask(ApexPages.StandardController controller)
    {}
        public void Search(){
        List<contact> ConList = New List<Contact>();
        
        String ThisQuery ='Select FirstName, Lastname , Email From Contact Where FirstName=:FirstName , LastName=:LastName , Email=:Email';
        ConList = Database.Query(ThisQuery);
       }
   
   }
Best Answer chosen by Aman Bisht
Amit Chaudhary 8Amit Chaudhary 8
Please update your code like below

Apex classes:-
 
public with sharing class SearchTask {
    Public String FirstName {Get;Set;}
    Public String LastName {Get;Set;}
    Public String Email {Get;Set;}
    Public String Query;
    Public List<contact> ConList { get;set;}
    
    public Void Searchtask(ApexPages.StandardController controller)
    {
        ConList = New List<Contact>();
    }

    public pageReference Search()
    {
        String ThisQuery ='Select FirstName, Lastname , Email From Contact Where FirstName=:FirstName or LastName=:LastName or Email=:Email';
        ConList = Database.Query(ThisQuery);
        return null;
    }
    
}

Pages:-
 
<apex:page Controller="SearchTask">
    <Apex:form >
    <apex:pageblock title="Search Contacts">
        
         <apex:pageblockButtons >
                 <apex:commandButton Action="{!Search}" value="Search"/>
          </apex:pageblockButtons>
            
           <h>FirstName</h> <apex:Inputtext Value="{!FirstName}"/>
           <h>lastName</h> <apex:InputText Value="{!LastName}"/>
           <h>Email</h> <apex:Inputtext Value="{!Email}"/>
    </apex:pageblock>
    <apex:pageblock title="Search Contacts">
        <apex:pageBlockTable value="{!ConList}" var="cont">
            <apex:column value="{!cont.FirstName }"/>
            <apex:column value="{!cont.Lastname }"/>
            <apex:column value="{!cont.Email }"/>
            
        </apex:pageBlockTable>
    </apex:pageblock>

    </Apex:form>
    
  
</apex:page>

User-added image

Let us know if this will help you

Thanks
Amit Chaudhary

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please your code like below
public with sharing class SearchTask {
Public String FirstName {Get;Set;}
Public String LastName {Get;Set;}
Public String Email {Get;Set;}
Public String Query;
    public Void Searchtask(ApexPages.StandardController controller)
    {}
        public void Search(){
        List<contact> ConList = New List<Contact>();
        
        String ThisQuery ='Select FirstName, Lastname , Email From Contact Where FirstName=:FirstName or LastName=:LastName or Email=:Email';
        ConList = Database.Query(ThisQuery);
       }
   
   }
Please add AND or OR according to your requirement

 
Aman BishtAman Bisht
not gettting any error btut no output is showing after entering the name
Aman BishtAman Bisht
<apex:page Controller="SearchTask">
    <Apex:form >
    <apex:pageblock title="Search Contacts">
        
         <apex:pageblockButtons >
         <apex:commandButton Action="{!Search}" value="Search"/>
             </apex:pageblockButtons>
            
           <h>FirstName</h> <apex:Inputtext Value="{!FirstName}"/>
           <h>lastName</h> <apex:InputText Value="{!LastName}"/>
           <h>Email</h> <apex:Inputtext Value="{!Email}"/>
            
            
    </apex:pageblock>
    </Apex:form>
    
  
</apex:page>

this is frontend
Aman BishtAman Bisht
posted above...
Amit Chaudhary 8Amit Chaudhary 8
Please update your code like below

Apex classes:-
 
public with sharing class SearchTask {
    Public String FirstName {Get;Set;}
    Public String LastName {Get;Set;}
    Public String Email {Get;Set;}
    Public String Query;
    Public List<contact> ConList { get;set;}
    
    public Void Searchtask(ApexPages.StandardController controller)
    {
        ConList = New List<Contact>();
    }

    public pageReference Search()
    {
        String ThisQuery ='Select FirstName, Lastname , Email From Contact Where FirstName=:FirstName or LastName=:LastName or Email=:Email';
        ConList = Database.Query(ThisQuery);
        return null;
    }
    
}

Pages:-
 
<apex:page Controller="SearchTask">
    <Apex:form >
    <apex:pageblock title="Search Contacts">
        
         <apex:pageblockButtons >
                 <apex:commandButton Action="{!Search}" value="Search"/>
          </apex:pageblockButtons>
            
           <h>FirstName</h> <apex:Inputtext Value="{!FirstName}"/>
           <h>lastName</h> <apex:InputText Value="{!LastName}"/>
           <h>Email</h> <apex:Inputtext Value="{!Email}"/>
    </apex:pageblock>
    <apex:pageblock title="Search Contacts">
        <apex:pageBlockTable value="{!ConList}" var="cont">
            <apex:column value="{!cont.FirstName }"/>
            <apex:column value="{!cont.Lastname }"/>
            <apex:column value="{!cont.Email }"/>
            
        </apex:pageBlockTable>
    </apex:pageblock>

    </Apex:form>
    
  
</apex:page>

User-added image

Let us know if this will help you

Thanks
Amit Chaudhary
This was selected as the best answer
Aman BishtAman Bisht
Thanks a lot
Aman BishtAman Bisht
I want to make link on account name??