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
Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student 

Please Help with Test Code for custom lookup class

Hey there,

I have a bit of code for a controller which I found online. This was created by Jeff Douglas as a means of creating a custom lookup. I have written loads of standard controler test classes, but i have never written one for a custom controller. i was hoping i could get a hand in writing one.

Thank you in advance for your time, below is my code:
 
public with sharing class CustomEPELookupController {
    
  public EPE_Course__c EPE {get;set;} // new EPE to create
  public List<EPE_Course__c> results{get;set;} // search results
  public string searchString{get;set;} // search keyword
  
  public CustomEPELookupController() {
    EPE = new EPE_Course__c();
    // get the current search string
    searchString = System.currentPageReference().getParameters().get('lksrch');
    runSearch();  
  }
   
  // performs the keyword search
  public PageReference search() {
    runSearch();
    return null;
  }
  
  // prepare the query and issue the search command
  private void runSearch() {
    // TODO prepare query string for complex serarches & prevent injections
    results = performSearch(searchString);               
  } 
  
  // run the search and return the records found. 
  private List<EPE_Course__c> performSearch(string searchString) {
 
    String soql = 'select id, name from EPE_Course__c';
    if(searchString != '' && searchString != null)
      soql = soql +  ' where name LIKE \'%' + searchString +'%\'';
    soql = soql + ' limit 25';
    System.debug(soql);
    return database.query(soql); 
 
  }
  
  // save the new account record
  public PageReference saveEPE() {
    insert EPE;
    // reset the account
    EPE = new EPE_Course__c();
    return null;
  }
  
  // used by the visualforce page to send the link to the right dom element
  public string getFormTag() {
    return System.currentPageReference().getParameters().get('frm');
  }
    
  // used by the visualforce page to send the link to the right dom element for the text box
  public string getTextBox() {
    return System.currentPageReference().getParameters().get('txt');
  }
 
}

 
Best Answer chosen by Developer.mikie.Apex.Student
DeveloperSalesforceDeveloperSalesforce
Test class for custom controller will be the same like standard controller...except the way you instantiate the controller

standard controller:
ApexPages.StandardController sC2 = new ApexPages.standardController(oRS);
 ProductController r oC2 = new ProductController (sC2);


custom controller:
ProductController x = new ProductController();