+ Start a Discussion
SolidLucasSolidLucas 

query is not returning value visualforce

Well i'm developing a visualforce page where have a query that returns the value of the fields of my account object, but is not returning nothing on my search. someone could help me?

visualforce page

 

<apex:page standardController="account" extensions="AccountSearch_clt">

    <apex:sectionHeader title="Pesquisa de Cliente" />
    <apex:form id="theform">
        <apex:pagemessages escape="false" id="messages" />
        <apex:pageBlock title="Pesquisa de Cliente ERP" >
        	
            <apex:pageBlockSection columns="2" >
                <apex:pageBlockSection columns="1" >
                    <apex:inputText value="{!PesquisaCodCliente}" label="Codigo Cliente/Endereco">
                        <apex:inputText value="{!PesquisaCodEndereco}" /> -&nbsp; &nbsp;&nbsp;
                    </apex:inputText>
                    <apex:inputText value="{!cia}" label="Cia/Documento">
                        <apex:inputText value="{!tipoDocumento}" html-autocomplete="off" /> -&nbsp; &nbsp;
                    </apex:inputText>
                    <apex:inputText value="{!NumeroDocumento}" label="Numero Documento/ Razao Social">
                        <apex:inputText value="{!RazaoSocial}" html-autocomplete="off" /> -&nbsp; &nbsp;
                    </apex:inputText>
                    <apex:inputText value="{!NomeFantasia}" label="Nome Fantasia/ CEP">
                        <apex:inputText value="{!RazaoSocial}" html-autocomplete="off" /> -&nbsp; &nbsp;
                    </apex:inputText>
                </apex:pageBlockSection>
            </apex:pageBlockSection>
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Pesquisar" action="{!doSearch}" rerender="theform" />
                <apex:commandButton value="Cancelar" action="{!cancel}" style="color:red;" />
            </apex:pageBlockButtons>
        </apex:pageBlock>
        
        <c:PageBlockTableEnhancerADV targetPbTableIds="pbt" pageSizeOptions="5,10,15,30" defaultPageSize="5" enableExport="false" />
        <apex:pageBlock mode="maindetail" id="pb">
            <apex:pageblockTable value="{!listAccPesquisa}" var="item" id="pbt">
                <apex:column value="{!item.CustomerNumber__c}" />
                <apex:column value="{!item['Name']}"/> 
                <apex:column value="{!item.Id}" />
                <apex:column value="{!item .Tipo_de_Documento__c}" />
            </apex:pageblockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
public with sharing class AccountSearch_clt {	

	public string NomeFantasia 	  	  {get;set;}  
	public string Pesquisastring	  {get;set;}
	public string PesquisaCodCliente  {get;set;}
	public string PesquisaCodEndereco {get;set;}
	public string cia				  {get;set;}
	public string tipoDocumento		  {get;set;}
	public string RazaoSocial		  {get;set;}
	public string NumeroDocumento	  {get;set;}
	public string Temp 				  {get;set;}
	public list <Account> listAccPesquisa{get;set;} 
	
   /**********
   	construtor
   	contructor
   ***********/
   public AccountSearch_clt(ApexPages.StandardController controller) {  

   }  

   public void getAccounts(){

   	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(NomeFantasia != '' && NomeFantasia!=null){
     					 	if(stringComplemento!=''){
     					 		stringComplemento += ' and ';
     					 	}else{
     					 		stringComplemento += ' where ';
     					 	}
     						stringComplemento += ' NomeFantasia__c LIKE '+ '\'' +NomeFantasia+'\'';  
     					}
     					 
     					if(PesquisaCodCliente!= ''){
     						if(stringComplemento!=''){
     					 		stringComplemento += ' and ';
     					 	}else{
     					 		stringComplemento += ' where ';
     					 	}  
     						stringComplemento += ' CustomerNumber__c LIKE '+ '\'' +PesquisaCodCliente+'\'';
     					}
     					
     					if(PesquisaCodEndereco!= ''){
     						if(stringComplemento!=''){
     					 		stringComplemento += ' and ';
     					 	}else{
     					 		stringComplemento += ' where ';
     					 	}
     						stringComplemento += ' SiteNumber__c LIKE '+ '\'' +PesquisaCodEndereco+'\'';  
     					}
     					
     					if(cia!= ''){
     						if(stringComplemento!=''){
     					 		stringComplemento += ' and ';
     					 	}else{
     					 		stringComplemento += ' where ';
     					 	}
     						stringComplemento += ' Cia__c LIKE '+ '\'' +cia+'\'';  
     					}
     					
     					if(tipoDocumento!= ''){
     						if(stringComplemento!=''){
     					 		stringComplemento += ' and ';
     					 	}else{
     					 		stringComplemento += ' where ';
     					 	}
     						stringComplemento += ' Tipo_de_Documento__c LIKE '+ '\'' +tipoDocumento+'\'';  
     					}
     					
     					if(RazaoSocial!= ''){
     						if(stringComplemento!=''){
     					 		stringComplemento += ' and ';
     					 	}else{
     					 		stringComplemento += ' where ';
     					 	}
     						stringComplemento += ' RazaoSocial__c LIKE '+ '\'' +RazaoSocial+'\'';  
     					}
     					
     					if(NumeroDocumento!= ''){
     						if(stringComplemento!=''){
     					 		stringComplemento += ' and ';
     					 	}else{
     					 		stringComplemento += ' where ';
     					 	}
     						stringComplemento += ' N_mero_do_Documento__c LIKE '+ '\'' +NumeroDocumento+'\'';  
     					}
     					
     			searchquery =  searchquery + stringComplemento;   
     			Temp=searchquery ;
     			listAccPesquisa = Database.query(searchquery);
   }
   

   public void doSearch(){
  	 	getAccounts();   	
   } 
}

 
Best Answer chosen by SolidLucas
Shashikant SharmaShashikant Sharma
I would suggest you to check your query "searchquery" and run it in developer console and se if it returns the results. If not then remove filters one by one and see which removal one gives you records. Once you trace it then check the codition in the code and correct it.

All Answers

EnreecoEnreeco
Are you sure you have access to the records?
The "with sharing" prevents to access records that are not shared with the running user.

--
May the Force.com be with you!
Shashikant SharmaShashikant Sharma
I would suggest you to check your query "searchquery" and run it in developer console and se if it returns the results. If not then remove filters one by one and see which removal one gives you records. Once you trace it then check the codition in the code and correct it.
This was selected as the best answer