I have a VF page which should display the opportunity data but when I search for the data using the input field i am not able to see any output and it's not displaying any output even it has the data .

VF page:

<apex:page controller="SearchController" >
<apex:form >
<apex:pageBlock Title="Edit opportunity details">
<apex:pageBlockSection >
<apex:pageBlockSectionItem >

<apex:outputLabel value="Opportunity Name" for="oppid"> </apex:outputLabel>
<apex:inputText id="oppid"/>
<apex:commandButton value="Search" action="{!executesearch}"/>


<apex:pageblock title="searched opportunities" rendered="{!searched}">

<apex:pageBlockTable value="{!opportunity}" var="opp">

<apex:column value="{!opp.StageName}"/>
<apex:column value="{!opp.Type}"/>
<apex:column value="{!opp.Name}"/>




Apex controller:

public class SearchController{
public string name{get;set;}
public boolean searched {get;set;}
public list<Opportunity> opportunity {get;set;}
public SearchController(){ //zero arugument constuctor

 public pagereference executesearch(){
 string searchstr = '%'+ name +'%';
 opportunity =[select StageName,Name,Type from  Opportunity where Name like :searchstr];
   return null;


Can anyone help me what is wrong with the code here


In the apex:input set the value as {!name} this will ensure any change made in the search input will be available in the apex controller. It should look like this -

<apex:inputText id="oppid" value="{!name}"/>

This should fix the issue.

  • In addition, avoid using variable names which are also sObject api names or reserved keywords as a best practice. And try using LWC for any new development. – Shashank Shastri Jun 18 at 14:49
  • Yah its correct the apex input should be as <apex:inputText id="oppid" value="{!name}"/> I will try to avoid any reserved keywords. – vijay Jun 18 at 14:56

The issues is with inputText it should be as

<apex:inputText id="oppid" value="{!name}"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.