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
RudiHulsbosRudiHulsbos 

Multi Select Picklist and APEX and Visualforce

HI,

 

We have a visualforce page with 3 multi select picklists for the user to select from. We construct the search query in the controller and 'includes', but we get the following error on submission:

 

System.QueryException: expecting a left parentheses, found ':'

Class.searchContact.doSearch: line 175, column 21 External entry point

 

Here is the code for the controller:

 

public class searchContact {
   public String API { get; set; }
   public String apiSessionId {get;set;} 
   public String apiServerURL {get;set;}

  string selectedrating;
  string searchString;
  string recType = 'Candidate';
  string[] grades;
  string[] specialities;
  string[] locations;
  string gmcreg;
  string segment;
  boolean w4f;
  boolean hotdoc;
 
  List<Contact> results;
 
  private final Contact contact;
 
  public searchContact() {
     contact = [SELECT Id, LastName, FirstName, Salutation, Name, MobilePhone, LastModifiedDate, LastActivityDate, a__Rating__c, Doc_Rating__c,
                GMC_reg__c, Grade_s__c, Hot_doc__c, Locations__c, Nationality__c, Speciality__c, Worked_4_Fresh__c, Avail_W_E__c,
                Avail_F_T__c, Avail_from__c, Avail_Updated__c, Segment__c, Job_Ends__c, Current__c, Account.Type, RecordType.Name,
                RecordType.Description, Owner.Username, Owner.LastName, Owner.FirstName, LastModifiedBy.Username, LastModifiedBy.LastName,
                LastModifiedBy.FirstName FROM Contact where RecordType.Name='Candidate' limit 1];
  }
 
  public Contact getContact() {
    return contact;
  }
 
  public String[] getGrades() {
     if (contact.Grade_s__c == null || contact.Grade_s__c == '') {     
       //apexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'Please select one or more grade first.'));     
        grades = null;     
     }
     else
     {   
     grades = contact.Grade_s__c.split(';',0);   
     }
     return grades; 
  }
 
   public String[] getSpecialities() {
    
       if (contact.Speciality__c == null || contact.Speciality__c == '') {     
        specialities = null;     
     }
     else
     {     
     specialities = contact.Speciality__c.split(';',0);  
     }
     return specialities;
  }
 
    public String[] getLocations() {
    
       if (contact.Locations__c == null || contact.Locations__c == '') {     
        locations= null;     
     }
     else
     {     
     locations= contact.Locations__c.split(';',0);  
     }
     return locations;
  }
 
  public String getSegment() {
    
       if (contact.Segment__c == null || contact.Segment__c == '') {     
        segment= null;     
     }
     else
     {     
     segment= contact.Segment__c;  
     }
     return segment;
  }

  public String getGMCReg() {
    
       if (contact.GMC_reg__c == null || contact.GMC_reg__c == '') {     
        gmcreg= null;     
     }
     else
     {     
     gmcreg= contact.GMC_reg__c;  
     }
     return gmcreg;
  }
 
    public List<SelectOption> getItems() {
    List<SelectOption> options = new List<SelectOption>();
   
    options.add(new SelectOption('0','--None--'));
    options.add(new SelectOption('1','1'));
    options.add(new SelectOption('2','2'));
    options.add(new SelectOption('3','3'));
    options.add(new SelectOption('4','4'));
    //options.add(new SelectOption('5','5'));
   
    return options;
  }
 
  public String getSelectedRating() {
    return selectedrating;
  }
 
  public void setSelectedRating(String selectedrating) {
    this.selectedrating = selectedrating;
  }   
     
  public Boolean getW4F() {  
     w4f = contact.Worked_4_Fresh__c;  
     return w4f ;
  }
 
    public Boolean getHotDoc() {  
     hotdoc= contact.Hot_doc__c;  
     return hotdoc;
  }
 
  public List<Contact> getResults() {   
    return results;
  }
 
  public PageReference doSearch() {
     results=null;
    
    searchString = 'SELECT Grade_s__c, Speciality__c, Locations__c, Segment__c, GMC_reg__c, a__Rating__c, Worked_4_Fresh__c, Contact_Link__c, Id, Name, LastName, FirstName, MobilePhone, Doc_Rating__c, Current__c, Hot_doc__c, Avail_F_T__c, Avail_W_E__c, Avail_from__c, Job_Ends__c, Avail_Updated__c, LastModifiedBy.Username, LastModifiedDate, Owner.Username, LastActivityDate, Nationality__c FROM Contact where RecordType.Name=:recType';

     getGrades(); 
     getSpecialities();
     getLocations();
     getSegment();
     getGMCReg();
     getSelectedRating();
     getW4F();
     getHotDoc();
    
    
     if (grades != null && grades.size() > 0)    {            
             searchString += ' and Grade_s__c includes :grades';
     }
    
     if (specialities!= null && specialities.size() > 0)    {
       searchString += ' and Speciality__c includes :specialities';
     }
          
      if (locations!= null && locations.size() > 0)    {
       searchString += ' and Locations__c includes :locations';
     }
    
       if (segment!= null)    {
              searchString += ' and Segment__c = :segment';
     }
       if (gmcreg!= null)  {
              searchString += ' and GMC_reg__c = :gmcreg';
     }         
    
     if (selectedrating != null && selectedrating != '0')    {
              searchString += ' and Doc_Rating__c  = :selectedrating';
     }        
     
      if (w4f != false)    {
              searchString += ' and Worked_4_Fresh__c  = :w4f';
     }
      if (hotdoc != false)    {
              searchString += ' and Hot_doc__c  = :hotdoc';
     }
         
          apexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, searchString));
 
          results = Database.query(searchString);
          if (results.size() == 0) {
            apexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'Sorry, no results for current selected criteria')); 
          }
          else
          {
            apexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'Count : '+ results.size())); 
          }
     return null;      
  }
 
  public PageReference doSend() {
    return null;
  }    
 
 
}

 

Please Help!!

 

Thanks,

 

Rudster

 

micwamicwa

Try this syntax instead of the ":" notation:

 

searchString += ' and GMC_reg__c =\''+gmcreg+'\'';

 

 

 

Richie DRichie D

Remember to escape your single quotes just in case!

 

gmcreg = string.escapeSingleQuotes (gmcreg);