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
Pritam ShekhawatPritam Shekhawat 

Dynamic Search - OnKeyUp / SOQL escapeSingleQuotes

hii,
I'm working on a project for a dynamic search of clients using Jeff Douglas's blog as a template

http://blog.jeffdouglas.com/2010/07/13/building-a-dynamic-search-page-in-visualforce/

I have everything displayed correctly, but in controller am not able to retrive dynamic picklist value.

https://jeffdouglas-developer-edition.na5.force.com/examples/CustomerSearch
i used  contact LeadSource Picklist Value in this controller.
Tell me how to retrive dynamic picklist value .its show Error: Compile Error: Invalid type: Schema.DescribeFieldResult at line 85 column 9
public with sharing class ContactSearchController {

  // the soql without the order and limit
  private String soql {get;set;}
  // the collection of contacts to display
  public List<Contact> contacts {get;set;}

  // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }

  // the current field to sort by. defaults to last name
  public String sortField {
    get  { if (sortField == null) {sortField = 'lastName'; } return sortField;  }
    set;
  }

  // format the soql for display on the visualforce page
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }

  // init the controller and display some sample data when the page loads
  public ContactSearchController() {
  contacts= new List<Contact>();
    soql = 'select FirstName, LastName,account.name,LeadSource FROM Contact Where account.Name!=null';
    runQuery();
  }

  // toggles the sorting of query from asc<-->desc
  public void toggleSort() {
    // simply toggle the direction
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
    // run the query again
    runQuery();
  }

  // runs the actual query
  public void runQuery() {

    try {
      contacts = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    } catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
    }

  }

  // runs the search with parameters passed via Javascript
  public PageReference runSearch() {
      
    String FirstName = Apexpages.currentPage().getParameters().get('FirstName');
    String LastName = Apexpages.currentPage().getParameters().get('LastName');
   
    String LeadSource = Apexpages.currentPage().getParameters().get('LeadSource ');
    
    String accountName= Apexpages.currentPage().getParameters().get('accountName');
   
  

    soql = 'select  FirstName,LastName,LeadSource,account.name FROM Contact Where account.Name!=null';
   
    if (FirstName!= null && !FirstName.equals(''))
      soql += ' and FirstName LIKE \''+String.escapeSingleQuotes(FirstName)+'%\'';
    if (LastName!= null && !LastName.equals(''))
      soql += ' and LastName LIKE \''+String.escapeSingleQuotes(LastName)+'%\'';
    if (accountName!= null && !accountName.equals(''))
      soql += ' and account.Name LIKE \''+String.escapeSingleQuotes(accountName)+'%\'';
    if (LeadSource !=null && !LeadSource.equals(''))
      soql += ' and LeadSource LIKE \''+String.escapeSingleQuotes(LeadSource)+'%\'';  
  
    // run the query again
    runQuery();

    return null;
  }
 public List<String> LeadSource{
    get {
      if (LeadSource== null) {
 
        LeadSource= new List<String>();
        Schema.DescribeFieldResult field = Contact.LeadSource.getDescribe();
 
        for (Schema.PicklistEntry b : field.getPicklistValues())
          LeadSource.add(b.getLabel());
 
      }
      return LeadSource;          
    }
    set;
  }
 
}

 
Best Answer chosen by Pritam Shekhawat
Pritam ShekhawatPritam Shekhawat
Thanx ForceLogic, 
                          Finally i solveout my problem, actually there are some problem with my developer org. so its show  compile error . I used another developer org its works finally :)

All Answers

EnreecoEnreeco
Which API version has the page?

--
May the Force.com be with you!
Pritam ShekhawatPritam Shekhawat
hi forcelogic , am using Salesforce.com API32.0 in both page and apex class.
EnreecoEnreeco
I tried to compile  your class and tried to call manually the "controller.LeadSource" getter and had not problem at all !
Pritam ShekhawatPritam Shekhawat
how to call manually ?? whenever am try to compile this .its show Error: Compile Error: Invalid type: Schema.DescribeFieldResult at line 85 column 9
EnreecoEnreeco
I simply saved your class and anonymously executed (developer console):
ContactSearchController controller = new ContactSearchController();
System.debug(controller.LeadSource);

 
Pritam ShekhawatPritam Shekhawat
dont know why but it still showing Compile Error: Invalid type: Schema.DescribeFieldResult at line 85 column 9 ??
EnreecoEnreeco
can you past the "meta.xml" file of the class?
Pritam ShekhawatPritam Shekhawat
Thanx ForceLogic, 
                          Finally i solveout my problem, actually there are some problem with my developer org. so its show  compile error . I used another developer org its works finally :)
This was selected as the best answer
EnreecoEnreeco
Great to hear it!