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
SolidLucasSolidLucas 

Query search help

Hello guys, well i'm trying to develop a visualforce page that contains some inputFields to do a query on my page, well i've created the page and the method to do the query but is not returning the values of the specific fields, the code bellow i've just put two inputfields to test the method but is not working someone could help me?

that is my controller
public with sharing class AccountSearch_clt {
	
public list <account> acc 	      	  {get;set;}
	public string PesquisaCliente 	  {get;set;}  
	public string Pesquisastring	  {get;set;}
	public string PesquisaCodCliente  {get;set;}
	public string PesquisaCodEndereco {get;set;} 
	 
   
   /**********
   	construtor
   	contructor
   ***********/
   public AccountSearch_clt(ApexPages.StandardController controller) {  

   }  
   
   /**********
   	Metodo que realiza faz a filtragem dos campos a serem pesquisados 
   	Method that performs the filtering of the fields to be searched
   ***********/
   public void search(){  
   	String stringComplemento = '';
     string searchquery='SELECT name,id,Tipo_de_Documento__c,SiteNumber__c,RazaoSocial__c,NomeFantasia__c,'+
     					'N_mero_do_Documento__c,CustomerNumber__c,Cia__c FROM account';
     					if(PesquisaString!= ''){
     						stringComplemento = 'WHERE name LIKE \'%+PesquisaString+%\'';  
     					}
     					 if(PesquisaCliente!= ''){
     						stringComplemento = 'WHERE NomeFantasia__c LIKE \'%+PesquisaCliente+%\'';  
     					}
     					
     					if(PesquisaCodCliente!= ''){
     						stringComplemento = 'WHERE CustomerNumber__c LIKE \'%+PesquisaCodCliente+%\'';  
     					}
     					
     					if(PesquisaCodEndereco!= ''){
     						stringComplemento = 'WHERE SiteNumber__c LIKE \'%+PesquisaCodEndereco+%\'';  
     					}
     					
     acc= Database.query(searchquery);   
   }
   public void clear(){  
   acc.clear();  
   } 	
}
My visualforce Page
<apex:page standardController="account" extensions="AccountSearch_clt">  
  	<apex:sectionHeader title="{!$ObjectType.Account.Label}" subtitle="Teste" />
  		<apex:form >  
 			<apex:inputText value="{!PesquisaString}" label="código Erp" html-autocomplete="off"/>
 			<apex:inputText value="{!PesquisaCliente}" label="Cliente" html-autocomplete="off"/>  
  				<apex:commandButton value="Pesquisar" action="{!search}"/>   
   					<apex:pageBlock title="Resultado da Pesquisa">  
    		<apex:pageblockTable value="{!acc}" var="a" border="0">
     			<apex:column headerValue="Conta" >  
      				<apex:outputlink  value="https://ap1.salesforce.com/{!a.id}" >{!a.Name}</apex:outputlink>
      				<apex:outputlink  value="https://ap1.salesforce.com/{!a.Tipo_de_Documento__c}"></apex:outputlink>
      				<apex:outputlink  value="https://ap1.salesforce.com/{!a.SiteNumber__c}"></apex:outputlink>
      				<apex:outputlink  value="https://ap1.salesforce.com/{!a.SiteNumber__c}"></apex:outputlink>
      				<apex:outputlink  value="https://ap1.salesforce.com/{!a.NomeFantasia__c}"></apex:outputlink> 
      				<apex:outputlink  value="https://ap1.salesforce.com/{!a.N_mero_do_Documento__c}"></apex:outputlink>   
     			</apex:column>  
     			
     			<apex:column  value="{!a.id}"/> 
     			<apex:column  value ="{!a.Tipo_de_Documento__c}"/>  
     			<apex:column  value ="{!a.SiteNumber__c}"/>  
     			<apex:column  value ="{!a.RazaoSocial__c}"/>
     			<apex:column  value ="{!a.NomeFantasia__c}"/>    
     			<apex:column  value ="{!a.N_mero_do_Documento__c}"/>   
    		</apex:pageBlockTable>     
   		</apex:pageBlock>  
  	</apex:form>  
 </apex:page>



 
Best Answer chosen by SolidLucas
BalajiRanganathanBalajiRanganathan
Put the searchquery in the Debug (System.debug(searchquery )) and see the final SOQL. it should execute in the query browser.
1) As of now you have to add a space after "From Account" in your SOQL.
2) are u going to support only one input? or Multiple. if multiple inputs are not null, then it will be invalid SOQL, you have to revist your logic