• hansa
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

Hi,

 

I have created a dynamic search page using isualforce which functions exactly how I want it to.  However, the only issue I have is that I want the search page to only display records for a particular recordType.  Any idea how this can be achieved?

 

I would greatly appreciate any help please.

 

Thanks in advance.   

 

Here is my Apex coding...

public with sharing class RemedySearchController {
 
  // the soql without the order and limit
  private String soql {get;set;}
  // the collection of cases to display
  public List<Case> cases {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 Account Name
  public String sortField {
    get  { if (sortField == null) {sortField = 'account.name'; } 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 RemedySearchController() {
    soql = 'select CaseNumber, Model_Number__c, Engine_s_n__c, contact.Name, Serial_Number_New__r.Name, Product_Group__c, Status, THD_Team__c, Priority, Group_Brand__c, X2wd_4w__c, Affected_Area__c, Part__c, Dealer_Customer_Question__c, Information_Source__c, Call_Source__c, Origin, Customer_Number__c, account.Name from case 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 {
      cases = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    } catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No Results Found!'));
    }
  }
 
  // runs the search with parameters passed via Javascript
  public PageReference runSearch() {
 
    String modelNumber = Apexpages.currentPage().getParameters().get('Model_Number__c');
    String engineNumber = Apexpages.currentPage().getParameters().get('Engine_s_n__c'); 
    String contactName = Apexpages.currentPage().getParameters().get('contactName');
    String accountName = Apexpages.currentPage().getParameters().get('accountName');
    String serialNumber = Apexpages.currentPage().getParameters().get('serialNumber');
    String thdTeam = Apexpages.currentPage().getParameters().get('thdTeam');
    String productGroup = Apexpages.currentPage().getParameters().get('productGroup');
    String status = Apexpages.currentPage().getParameters().get('status');
    String priority = Apexpages.currentPage().getParameters().get('priority');
    String groupBrand = Apexpages.currentPage().getParameters().get('groupBrand');
    String wheelDrive = Apexpages.currentPage().getParameters().get('wheelDrive');
    String affectedArea = Apexpages.currentPage().getParameters().get('affectedArea');
    String partNumber = Apexpages.currentPage().getParameters().get('partNumber');
    String caseNumber = Apexpages.currentPage().getParameters().get('caseNumber');
    String customerQuestion = Apexpages.currentPage().getParameters().get('customerQuestion');
    String infoSource = Apexpages.currentPage().getParameters().get('infoSource');
    String callSource = Apexpages.currentPage().getParameters().get('callSource');
    String caseOrigin = Apexpages.currentPage().getParameters().get('caseOrigin');
    String customerNumber = Apexpages.currentPage().getParameters().get('customerNumber');
    
    soql = 'select CaseNumber, Model_Number__c, Engine_s_n__c, contact.Name, Serial_Number_New__r.Name, Product_Group__c, Status, THD_Team__c, Priority, Group_Brand__c, X2wd_4w__c, Affected_Area__c, Part__c, Dealer_Customer_Question__c, Information_Source__c, Call_Source__c, Origin, Customer_Number__c, account.name from case where account.name != null';
    if (!modelNumber.equals(''))
      soql += ' and Model_Number__c LIKE \''+String.escapeSingleQuotes(modelNumber)+'%\'';
    if (!engineNumber.equals(''))
      soql += ' and Engine_s_n__c LIKE \''+String.escapeSingleQuotes(engineNumber)+'%\'';
    if (!accountName.equals(''))
      soql += ' and Account.name LIKE \''+String.escapeSingleQuotes(accountName)+'%\'';
    if (!contactName.equals(''))
      soql += ' and contact.Name LIKE \''+String.escapeSingleQuotes(contactName)+'%\'';
    if (!serialNumber.equals(''))
      soql += ' and Serial_Number_New__r.name LIKE \''+String.escapeSingleQuotes(serialNumber)+'%\'';
    if (!thdTeam.equals(''))
      soql += ' and THD_Team__c LIKE \''+thdTeam+'\'';
    if (!productGroup.equals(''))
      soql += ' and Product_Group__c LIKE \''+productGroup+'\'';
    if (!status.equals(''))
      soql += ' and status LIKE \''+status+'\'';
    if (!priority.equals(''))
      soql += ' and Priority LIKE \''+priority+'\'';
    if (!groupBrand.equals(''))
      soql += ' and Group_Brand__c LIKE \''+groupBrand+'\'';
    if (!wheelDrive.equals(''))
      soql += ' and X2wd_4w__c LIKE \''+wheelDrive+'\'';
    if (!affectedArea.equals(''))
      soql += ' and Affected_Area__c LIKE \''+affectedArea+'\'';
    if (!partNumber.equals(''))
      soql += ' and Part__c LIKE \''+String.escapeSingleQuotes(partNumber)+'%\'';
    if (!caseNumber.equals(''))
      soql += ' and CaseNumber LIKE \''+String.escapeSingleQuotes(caseNumber)+'%\'';
    if (!customerQuestion.equals(''))
      soql += ' and Dealer_Customer_Question__c LIKE \''+customerQuestion+'\'';
    if (!infoSource.equals(''))
      soql += ' and Information_Source__c LIKE \''+infoSource+'\'';
    if (!callSource.equals(''))
      soql += ' and Call_Source__c LIKE \''+callSource+'\'';
    if (!caseOrigin.equals(''))
      soql += ' and Origin LIKE \''+caseOrigin+'\'';
    if (!customerNumber.equals(''))
      soql += ' and Customer_Number__c LIKE \''+String.escapeSingleQuotes(customerNumber)+'%\'';
    
    // run the query again
    runQuery();
     return null;
  }

 // use apex describe to build the picklist values
  public List<String> productGroups {
    get {
      if (productGroups == null) {
 
        productGroups = new List<String>();
        Schema.DescribeFieldResult field = Case.Product_Group__c.getDescribe();
 
        for (Schema.PicklistEntry f : field.getPicklistValues())
          productGroups.add(f.getLabel());
 
      }
      return productGroups;          
    }
    set;
  }
     
    public List<String> statuses {
    get {
      if (statuses == null) {
 
        statuses = new List<String>();
        Schema.DescribeFieldResult field = Case.Status.getDescribe();
 
        for (Schema.PicklistEntry f : field.getPicklistValues())
          statuses.add(f.getLabel());
       }
      return statuses;          
    }
    set;
  }

    public List<String> thdTeams {
    get {
      if (thdTeams == null) {
 
        thdTeams = new List<String>();
        Schema.DescribeFieldResult field = Case.THD_Team__c.getDescribe();
 
        for (Schema.PicklistEntry f : field.getPicklistValues())
          thdTeams.add(f.getLabel());
       }
      return thdTeams;          
    }
    set;
  }
   
    public List<String> priorities {
    get {
      if (priorities == null) {
 
        priorities = new List<String>();
        Schema.DescribeFieldResult field = Case.Priority.getDescribe();
 
        for (Schema.PicklistEntry f : field.getPicklistValues())
          priorities.add(f.getLabel());
       }
      return priorities;          
    }
    set;
  }

    public List<String> groupBrands {
    get {
      if (groupBrands == null) {
 
        groupBrands = new List<String>();
        Schema.DescribeFieldResult field = Case.Group_Brand__c.getDescribe();
 
        for (Schema.PicklistEntry f : field.getPicklistValues())
        groupBrands.add(f.getLabel());
       }
      return groupBrands;          
    }
    set;
}
    
    public List<String> wheelDrives {
    get {
      if (wheelDrives == null) {
 
        wheelDrives = new List<String>();
        Schema.DescribeFieldResult field = Case.X2wd_4w__c.getDescribe();
 
        for (Schema.PicklistEntry f : field.getPicklistValues())
        wheelDrives.add(f.getLabel());
       }
      return wheelDrives;          
    }
    set;
}

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

   public List<String> customerQuestions {
    get {
      if (customerQuestions == null) {
 
        customerQuestions = new List<String>();
        Schema.DescribeFieldResult field = Case.Dealer_Customer_Question__c.getDescribe();
 
        for (Schema.PicklistEntry f : field.getPicklistValues())
        customerQuestions.add(f.getLabel());
       }
          return customerQuestions;          
    }
    set;
}
    
    public List<String> infoSources {
    get {
      if (infoSources == null) {
 
        infoSources = new List<String>();
        Schema.DescribeFieldResult field = Case.Information_Source__c.getDescribe();
 
        for (Schema.PicklistEntry f : field.getPicklistValues())
        infoSources.add(f.getLabel());
       }
          return infoSources;          
    }
    set;
}
    public List<String> callSources {
    get {
      if (callSources == null) {
 
        callSources = new List<String>();
        Schema.DescribeFieldResult field = Case.Call_Source__c.getDescribe();
 
        for (Schema.PicklistEntry f : field.getPicklistValues())
        callSources.add(f.getLabel());
       }
          return callSources;          
    }
    set;
}
    
    public List<String> caseOrigins {
    get {
      if (caseOrigins == null) {
 
        caseOrigins = new List<String>();
        Schema.DescribeFieldResult field = Case.Origin.getDescribe();
 
        for (Schema.PicklistEntry f : field.getPicklistValues())
        caseOrigins.add(f.getLabel());
       }
          return caseOrigins;          
    }
    set;
}
}
  • January 31, 2012
  • Like
  • 0