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
Pat WimsattPat Wimsatt 

Test Case for Controller

I'm stuck - again. LOL  I have an Apex page and Controller that I need to upload to Production. I have validated that it works correctly. However, to upload to Production it has to pass that "Test" condition and I don't know how to write it. I am not a C# guy.  Here is my controller, what would a test class look like?

public with sharing class LaneDetailCon {
    
    public String oCity { get; set; }
    public String dCity { get; set; }
    public Boolean searched {get; set;}
    
    public List<Lane_Detail__C> lanes { get; set; }
        
public LaneDetailCon(){ 
    searched=false;    
        String orCity = ApexPages.currentPage().getParameters().get('oCity');
        String dsCity = ApexPages.currentPage().getParameters().get('dCity');   
        if (null!=orCity)
        {
            oCity = orCity;
            dCity = dsCity;
            executeSearch();
        }
    }
    
public PageReference executeSearch(){
    searched=true;
     //   System.debug('The origin city is ' + oCity);
     //      System.debug('The destination city is ' + dCity);
        
           lanes =  [SELECT id, Origin_City__c, Origin_Statess__c, Destination_City__c, Destination_States__c, Rate__c, 
                     Opportunity__r.Name, Opportunity__r.AccountId, Opportunity__r.Date_Quoted__c, Opportunity__r.StageName 
                     FROM Lane_Detail__c
                     WHERE Origin_City__c = :oCity AND Destination_City__c = :dCity 
                     Order By Opportunity__r.Date_Closed__c Desc
                     LIMIT 25]; 
      //  System.debug('The SOQL is ' + lanes);
        return null;
    }
}
Best Answer chosen by Pat Wimsatt
AbhishekAbhishek (Salesforce Developers) 
https://salesforce.stackexchange.com/questions/230205/test-class-for-a-custom-controller

You can write the test call by taking the suggestions from the above developer discussion.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks.