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
gbrown17gbrown17 

Apex Class to search database

Hi,

 

I'm trying to create a public class that will search my object (production__c) by a phone number and display values of the custom object.

I want this controller to run on a VF page where all data in the object can be searched by the phone number.

 

I have some apex code that i've been tweaking, but it's not working.  The code I wrote is searching by the name.  I can always tweak it for a phone number on my own.

 

Can someone please shed some light on why this isn't working.  Bear with me, I'm a noob.

 

 public class VehicleStatusLookup {
public List<production__c> status{get;set;}
public List<production__c> getstatus(){
return status;
}
public production__c getstatus(){
Id id=system.currentpagereference().getparameters().get('id');
return id == null ? new production__c() : [SELECT Id, Name
FROM Production__c
WHERE Id = :id];
}
public String statusname { get; set; }
public String statusId { get; set; }

public PageReference search() {


if(statusId.length()>0)
{
string stdid='select id, name,Production__c,Status__c,Location__c from production__C where name=:statustId';
status=Database.Query(stdid);
if(status.size()==0)
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Vehicle Not Found'));
return null;
}
if(statusname.length()>0)
{
string stdname='select id,name,Production__c,Status__c,Location__c from production__C where Production__C LIKE \'' + Statusname+ '%\'';
status=Database.Query(stdname);
if(status.size()==0)
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Vehicle Not Found'));
return null;
}
if((statusId.length()>0)&&(statusname.length()>0))
{
string std='select id,name,Production__c,Status__c,Location__c where name=:statusId';
status=Database.Query(std);
return null;
}
else
{
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Please Enter Any Value'));
return null;
}
}
}

 

 

 

Thanks,


Greg

 

 

Shailesh DeshpandeShailesh Deshpande
Where are you setting the statusName and statusId properties? Is it done in the VF page? Can you post the code for. Your page as well? I dont see anything wrong with your class except, the second query. You are mising the ":" there.