+ Start a Discussion
SolidLucasSolidLucas 

Checkbox query problem

well guys i'm creating a visualforce that search some information on my account,i'm having trouble with the checkbox that i want to search the active users when the checkbox is marked and the inative i
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,Ativo__c FROM Account ';
     			
     				if(PesquisaString != '' && PesquisaString!=null){     						
     					stringComplemento = ' WHERE name LIKE '+ '\'%' +PesquisaString+'%\'';
     				}
     					
     			     if(NomeFantasia != '' && NomeFantasia!=null){
     					 	if(stringComplemento!=''){
     					 		stringComplemento += ' and ';
     					 	}else{
     					 		stringComplemento += ' where ';
     					 	}
     						stringComplemento += ' NomeFantasia__c LIKE '+ '\'' +NomeFantasia+'\'';  
     					}
     					 
     					if(PesquisaCodCliente!= '' && PesquisaCodCliente!=null){
     						if(stringComplemento!=''){
     					 		stringComplemento += ' and ';
     					 	}else{
     					 		stringComplemento += ' where ';
     					 	}  
     						stringComplemento += ' CustomerNumber__c LIKE '+ '\'' +PesquisaCodCliente+'\'';
     					}
     					
     					if(PesquisaCodEndereco!= '' && PesquisaCodEndereco!=null){
     						if(stringComplemento!=''){
     					 		stringComplemento += ' and ';
     					 	}else{
     					 		stringComplemento += ' where ';
     					 	}
     						stringComplemento += ' SiteNumber__c LIKE '+ '\'' +PesquisaCodEndereco+'\'';  
     					}
     					
     					if(cia!= '' && cia!=null){
     						if(stringComplemento!=''){
     					 		stringComplemento += ' and ';
     					 	}else{
     					 		stringComplemento += ' where ';
     					 	}
     						stringComplemento += ' Cia__c LIKE '+ '\'' +cia+'\'';  
     					}
     					
     					if(tipoDocumento!= '' && tipoDocumento!=null){
     						if(stringComplemento!=''){
     					 		stringComplemento += ' and ';
     					 	}else{
     					 		stringComplemento += ' where ';
     					 	}
     						stringComplemento += ' Tipo_de_Documento__c LIKE '+ '\'' +tipoDocumento+'\'';  
     					}
     					
     					if(RazaoSocial!= '' && RazaoSocial!=null){
     						if(stringComplemento!=''){
     					 		stringComplemento += ' and ';
     					 	}else{
     					 		stringComplemento += ' where ';
     					 	}
     						stringComplemento += ' RazaoSocial__c LIKE '+ '\'' +RazaoSocial+'\'';  
     					}
     					
     					if(NumeroDocumento!= '' && NumeroDocumento!=null){
     						if(stringComplemento!=''){
     					 		stringComplemento += ' and ';
     					 	}else{
     					 		stringComplemento += ' where ';
     					 	}
     						stringComplemento += ' N_mero_do_Documento__c LIKE '+ '\'' +NumeroDocumento+'\'';  
     					}
     					\********************* HERE IS WHERE I'M HAVING TROUBLE
                                      
     					if(ClienteAtivo){
     					
     						stringComplemento += 'WHERE Ativo__c = true ';  
     						
     					}
     				
     				
     			searchquery =  searchquery + stringComplemento;   
     			Temp=searchquery ;
     			listAccPesquisa = Database.query(searchquery);
   }

f is not.
Best Answer chosen by SolidLucas
BalajiRanganathanBalajiRanganathan
Also you are missing the logic which is in other filters
if (ClienteAtivo){ 

  if(stringComplemento!=''){ 
    stringComplemento += ' and ';
  } else { 
   stringComplemento += ' where ';
  }
  stringComplemento += 'Ativo__c = true '; 
}

 

All Answers

lakslaks
Hi,

Assuming that ClienteAtivo is the boolean variable that is set to true when the checkbox is checked, 
Is Ativo__c a boolean field or text ?
If it is a text field you'll have to mention 'true'

Regards,
Lakshmi.
BalajiRanganathanBalajiRanganathan
Also you are missing the logic which is in other filters
if (ClienteAtivo){ 

  if(stringComplemento!=''){ 
    stringComplemento += ' and ';
  } else { 
   stringComplemento += ' where ';
  }
  stringComplemento += 'Ativo__c = true '; 
}

 
This was selected as the best answer
SolidLucasSolidLucas
thanks balaji!