0

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:pageBlockSectionItem>
<apex:commandButton value="Search" action="{!executesearch}"/>

</apex:pageBlockSection>

</apex:pageBlock>
<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:pageBlockTable>

</apex:pageblock>
</apex:form>

</apex:page>

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
searched=false;


}
 
 public pagereference executesearch(){
 searched=true;
 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

2 Answers 2

2

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.

2
  • 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. Jun 18, 2021 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.
    – SFDCSai
    Jun 18, 2021 at 14:56
0

The issues is with inputText it should be as

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .