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
Akshay KopardeAkshay Koparde 

Not able to find out logical error in apex class

Hi All,

I am pretty new to salesforce. I have written a custom apex class to get the string data from visualforce page. This string is compared with records in database and displays on the screen. In my case I am performing this operation on Account object. I dont know why when I type input string(say industry type) in the input box created using Visualforce page and hit "Go!" button  the list of records dont populate in the table declared in visualforce code. Kindly suggest the changes needed.

VisualForce Code
<apex:page controller="search_accounts" >
<apex:form >
    <apex:pageBlock title="Account Search">
    <apex:inputText value="{!input_text}" />
    <apex:commandButton value="Go!"/>
    <apex:pageBlockTable value="{!search_result}" var="a">
        <apex:column value="{!a.Name}"/>
        <apex:column value="{!a.Type}"/>
        <apex:column value="{!a.Industry}"/>
        <apex:column value="{!a.Phone}"/>
    </apex:pageBlockTable>  
    </apex:pageBlock>
</apex:form>  
</apex:page>

Custom controller
public class search_accounts
{
    public string input_text;
    public list<Account> search_result;
    
    public string getinput_text()
    {
        return input_text;
    }
    public list<Account> getsearch_result()
    {
        return search_result;
    }
    
    public void setinput_text(string s)
    {
        input_text=s;
    }
    public PageReference Go()
    {
        search_result=[select Name, Type, Industry, Phone from Account Where Industry=:input_text];
        return NULL;
    }
}

 
Best Answer chosen by Akshay Koparde
sfdcMonkey.comsfdcMonkey.com
hi
try below code
<apex:page controller="search_accounts" >
<apex:form >
    <apex:pageBlock title="Account Search">
    <apex:inputText value="{!input_text}" />
    <apex:commandButton value="Go!" action="{!Go}"/>
    <apex:pageBlockTable value="{!search_result}" var="a">
        <apex:column value="{!a.Name}"/>
        <apex:column value="{!a.Type}"/>
        <apex:column value="{!a.Industry}"/>
        <apex:column value="{!a.Phone}"/>
    </apex:pageBlockTable>  
    </apex:pageBlock>
</apex:form>  
</apex:page>
 
public class search_accounts{  
    public string input_text{get;set;} // create get;set property for access it,in vf page 
    public list<Account> search_result {get;set;}
    
    public string getinput_text(){
        return input_text;
    }
    public list<Account> getsearch_result()
    {
        return search_result;
    }
    
    public void setinput_text(string s)
    {
        input_text=s;
    }
    public void Go(){
        search_result=[select Name, Type, Industry, Phone from Account Where Industry=:input_text];
      
    }
}

thanks
let me inform if it helps you and mark it best answer if it helps you so it make proper solution for others



 

All Answers

sfdcMonkey.comsfdcMonkey.com
hi
try below code
<apex:page controller="search_accounts" >
<apex:form >
    <apex:pageBlock title="Account Search">
    <apex:inputText value="{!input_text}" />
    <apex:commandButton value="Go!" action="{!Go}"/>
    <apex:pageBlockTable value="{!search_result}" var="a">
        <apex:column value="{!a.Name}"/>
        <apex:column value="{!a.Type}"/>
        <apex:column value="{!a.Industry}"/>
        <apex:column value="{!a.Phone}"/>
    </apex:pageBlockTable>  
    </apex:pageBlock>
</apex:form>  
</apex:page>
 
public class search_accounts{  
    public string input_text{get;set;} // create get;set property for access it,in vf page 
    public list<Account> search_result {get;set;}
    
    public string getinput_text(){
        return input_text;
    }
    public list<Account> getsearch_result()
    {
        return search_result;
    }
    
    public void setinput_text(string s)
    {
        input_text=s;
    }
    public void Go(){
        search_result=[select Name, Type, Industry, Phone from Account Where Industry=:input_text];
      
    }
}

thanks
let me inform if it helps you and mark it best answer if it helps you so it make proper solution for others



 
This was selected as the best answer
Akshay KopardeAkshay Koparde
@piyush_Jain Thanks.