+ Start a Discussion
vibrationvibration 

soql value comes in to null..

Hi,

 soql value comes in to null. please correct the code. 

 

class

 

public with sharing class SearchOpportunity {
  List<Opportunity> listopp = new List<Opportunity>();
Public String Oppname;
public String valopp {get; set;}

 public List<SelectOption> getOppname() {
     List<SelectOption> options = new List<SelectOption>();
   //  options.add(new SelectOption('None','None'));
     List<Opportunity> listpickOpp = new List<Opportunity>();
     listpickOpp = [Select id,name from Opportunity];         
     for(Opportunity objopp : listpickOpp){
     if(objopp.name != null){             
      options.add(new SelectOption(objopp.name,objopp.name));
      }
     }      
     return options;             
     }

public List<Opportunity> getresults() {
   return listopp;
   }

 public PageReference Search(){
 
   
   listopp =[select id,name,Stagename,Account.name,Amount,LeadSource,CloseDate__c,Probability,OpportunityCheck__c from Opportunity where name =:valopp]; --- value is null
 
 
   PageReference packagePage = new PageReference('/apex/VFResult');
   return(packagePage);
 
   }



page

 

<apex:page controller="SearchOpportunity">
<apex:sectionHeader title="Opportunity Search" subtitle="Opportunity Search"/>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Opportunity Search"  columns="7" collapsible="false">
     <apex:outputLabel Value="Opportunity Name" style="margin-left:1%;font-weight:bold;position:relative;bottom:5px" >     
     <apex:selectList value="{!valopp}" size="1"  style="margin-left:2%;position:relative;top:5px;">
     <apex:selectOptions value="{!Oppname}"/>
     </apex:selectList>    
     </apex:outputLabel>
<apex:commandButton value="Search" immediate="true" action="{!Search}" />
 </apex:pageBlockSection>
    <apex:pageBlock title="Search Results">
      <apex:pageBlockTable value="{!results}" var="sc">                              
            <apex:column headerValue="Select">
            <apex:inputCheckbox value="{!sc.OpportunityCheck__c}"/>
            </apex:column>           
            <apex:column headerValue="Opportunity Name" value="{!sc.Name}"/>
            <apex:column headerValue="Account Name" value="{!sc.Account.Name}"/>
            <apex:column headerValue="Lead Source" value="{!sc.LeadSource}"/>
            <apex:column headerValue="Stagename" value="{!sc.Stagename}"/>   
            <apex:column headerValue="Amount" value="{!sc.Amount}"/>    
            <apex:column headerValue="Probability" value="{!sc.Probability}"/>         
            </apex:pageBlockTable>
      </apex:pageBlock>         
</apex:pageBlock>
</apex:form>
</apex:page>

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

 

You’re running code. I have remove the custom field that is created by you in your org please add them in query (Apex controller) and in repeat (VF page).

 

------------ VF Page ----------------
<apex:page controller="SearchOpportunity">
<apex:sectionHeader title="Opportunity Search" subtitle="Opportunity Search"/>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Opportunity Search"  columns="7" collapsible="false">
     <apex:outputLabel Value="Opportunity Name" style="margin-left:1%;font-weight:bold;position:relative;bottom:5px" >     
     <apex:selectList value="{!valopp}" size="1"  style="margin-left:2%;position:relative;top:5px;">
     <apex:selectOptions value="{!Oppname}"/>
     </apex:selectList>    
     </apex:outputLabel>
<apex:commandButton value="Search" reRender="resulttable"   action="{!Search}" />
 </apex:pageBlockSection>
    <apex:pageBlock title="Search Results">
      <apex:pageBlockTable id="resulttable" value="{!results}" var="sc">                              
            <apex:column headerValue="Select">
             </apex:column>           
            <apex:column headerValue="Opportunity Name" value="{!sc.Name}"/>
            <apex:column headerValue="Account Name" value="{!sc.Account.Name}"/>
            <apex:column headerValue="Lead Source" value="{!sc.LeadSource}"/>
            <apex:column headerValue="Stagename" value="{!sc.Stagename}"/>   
            <apex:column headerValue="Amount" value="{!sc.Amount}"/>    
            <apex:column headerValue="Probability" value="{!sc.Probability}"/>         
            </apex:pageBlockTable>
      </apex:pageBlock>         
</apex:pageBlock>
</apex:form>
</apex:page>

--------------- Apex controller -------------

public with sharing class SearchOpportunity 
{

    public String getListopp() {
        return null;
    }

  List<Opportunity> listopp = new List<Opportunity>();
Public String Oppname;
public String valopp {get; set;}

 public List<SelectOption> getOppname() {
     List<SelectOption> options = new List<SelectOption>();
   //  options.add(new SelectOption('None','None'));
     List<Opportunity> listpickOpp = new List<Opportunity>();
     listpickOpp = [Select id,name from Opportunity];         
     for(Opportunity objopp : listpickOpp){
     if(objopp.name != null){             
      options.add(new SelectOption(objopp.name,objopp.name));
      }
     }      
     return options;             
     }

public List<Opportunity> getresults() {
   return listopp;
   }

 public void Search(){
 
   
   listopp =[select id,name,Stagename,Account.name,Amount,LeadSource,Probability from Opportunity where name =:valopp]; 
 
 
  
 }
   }

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 


All Answers

vibrationvibration

Hi,

 soql value comes in to null. please correct the code. 

 

class

 

public with sharing class SearchOpportunity {
  List<Opportunity> listopp = new List<Opportunity>();
Public String Oppname;
public String valopp {get; set;}

 public List<SelectOption> getOppname() {
     List<SelectOption> options = new List<SelectOption>();
   //  options.add(new SelectOption('None','None'));
     List<Opportunity> listpickOpp = new List<Opportunity>();
     listpickOpp = [Select id,name from Opportunity];         
     for(Opportunity objopp : listpickOpp){
     if(objopp.name != null){             
      options.add(new SelectOption(objopp.name,objopp.name));
      }
     }      
     return options;             
     }

public List<Opportunity> getresults() {
   return listopp;
   }

 public PageReference Search(){
 
   
   listopp =[select id,name,Stagename,Account.name,Amount,LeadSource,CloseDate__c,Probability,OpportunityCheck__c from Opportunity where name =:valopp]; --- value is null
 
 
   PageReference packagePage = new PageReference('/apex/VFResult');
   return(packagePage);
 
   }



page

 

<apex:page controller="SearchOpportunity">
<apex:sectionHeader title="Opportunity Search" subtitle="Opportunity Search"/>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Opportunity Search"  columns="7" collapsible="false">
     <apex:outputLabel Value="Opportunity Name" style="margin-left:1%;font-weight:bold;position:relative;bottom:5px" >     
     <apex:selectList value="{!valopp}" size="1"  style="margin-left:2%;position:relative;top:5px;">
     <apex:selectOptions value="{!Oppname}"/>
     </apex:selectList>    
     </apex:outputLabel>
<apex:commandButton value="Search" immediate="true" action="{!Search}" />
 </apex:pageBlockSection>
    <apex:pageBlock title="Search Results">
      <apex:pageBlockTable value="{!results}" var="sc">                              
            <apex:column headerValue="Select">
            <apex:inputCheckbox value="{!sc.OpportunityCheck__c}"/>
            </apex:column>           
            <apex:column headerValue="Opportunity Name" value="{!sc.Name}"/>
            <apex:column headerValue="Account Name" value="{!sc.Account.Name}"/>
            <apex:column headerValue="Lead Source" value="{!sc.LeadSource}"/>
            <apex:column headerValue="Stagename" value="{!sc.Stagename}"/>   
            <apex:column headerValue="Amount" value="{!sc.Amount}"/>    
            <apex:column headerValue="Probability" value="{!sc.Probability}"/>         
            </apex:pageBlockTable>
      </apex:pageBlock>         
</apex:pageBlock>
</apex:form>
</apex:page>

Navatar_DbSupNavatar_DbSup

Hi,

 

You have to remove immediate="true" or make its value as false from apex: commandButton. Instead use this only and it will work for you:

 

<apex:commandButton value="Search"  action="{!Search}"/>

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

Ankit AroraAnkit Arora

Just change your visualforce page command button code from :

 

<apex:commandButton value="Search" immediate="true" action="{!Search}" />

 To :

 

<apex:commandButton value="Search" action="{!Search}" />

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

vibrationvibration

Thanks

 

If i remove immediate= true , command button is not working.

Ankit AroraAnkit Arora

Please do not post the same content in multiple sections. I have merged both duplicate topics.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

Navatar_DbSupNavatar_DbSup

Hi,

 

You’re running code. I have remove the custom field that is created by you in your org please add them in query (Apex controller) and in repeat (VF page).

 

------------ VF Page ----------------
<apex:page controller="SearchOpportunity">
<apex:sectionHeader title="Opportunity Search" subtitle="Opportunity Search"/>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Opportunity Search"  columns="7" collapsible="false">
     <apex:outputLabel Value="Opportunity Name" style="margin-left:1%;font-weight:bold;position:relative;bottom:5px" >     
     <apex:selectList value="{!valopp}" size="1"  style="margin-left:2%;position:relative;top:5px;">
     <apex:selectOptions value="{!Oppname}"/>
     </apex:selectList>    
     </apex:outputLabel>
<apex:commandButton value="Search" reRender="resulttable"   action="{!Search}" />
 </apex:pageBlockSection>
    <apex:pageBlock title="Search Results">
      <apex:pageBlockTable id="resulttable" value="{!results}" var="sc">                              
            <apex:column headerValue="Select">
             </apex:column>           
            <apex:column headerValue="Opportunity Name" value="{!sc.Name}"/>
            <apex:column headerValue="Account Name" value="{!sc.Account.Name}"/>
            <apex:column headerValue="Lead Source" value="{!sc.LeadSource}"/>
            <apex:column headerValue="Stagename" value="{!sc.Stagename}"/>   
            <apex:column headerValue="Amount" value="{!sc.Amount}"/>    
            <apex:column headerValue="Probability" value="{!sc.Probability}"/>         
            </apex:pageBlockTable>
      </apex:pageBlock>         
</apex:pageBlock>
</apex:form>
</apex:page>

--------------- Apex controller -------------

public with sharing class SearchOpportunity 
{

    public String getListopp() {
        return null;
    }

  List<Opportunity> listopp = new List<Opportunity>();
Public String Oppname;
public String valopp {get; set;}

 public List<SelectOption> getOppname() {
     List<SelectOption> options = new List<SelectOption>();
   //  options.add(new SelectOption('None','None'));
     List<Opportunity> listpickOpp = new List<Opportunity>();
     listpickOpp = [Select id,name from Opportunity];         
     for(Opportunity objopp : listpickOpp){
     if(objopp.name != null){             
      options.add(new SelectOption(objopp.name,objopp.name));
      }
     }      
     return options;             
     }

public List<Opportunity> getresults() {
   return listopp;
   }

 public void Search(){
 
   
   listopp =[select id,name,Stagename,Account.name,Amount,LeadSource,Probability from Opportunity where name =:valopp]; 
 
 
  
 }
   }

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 


This was selected as the best answer
vibrationvibration

Thanks...