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
tzuvytzuvy 

Test Methods for Extensions

Hi,

 

I'm trying to write a controller extemsion. I want to show a list of records related to a case's specific field.

 

For this I wrote the following:

 

public with sharing class CaseObjectController {



   
    private final Case caseObj;
    transient List<Account_Hot_News__c> caseNews;
     date todaysDate = date.today();
    
    public CaseObjectController(ApexPages.StandardController stdController) {
        this.caseObj = (Case)stdController.getRecord();
    }

    public List<Account_Hot_News__c> getNewsForCases() {
       
        
        if (caseNews == null) {
            
            
                return [
                select   Id, Account_s_Main_SiteID__c, Alert_Message__c,  name, Expires_On__c, Affecting_All_Servers__c, Account_s_Server_Name__c
                from Account_Hot_News__c
                where  (Account_Hot_News__c.Account_s_Main_SiteID__c = :caseObj.Case_Site_ID__c AND (Expires_On__c >= : todaysDate OR Expires_On__c = NULL ) ) OR (Affecting_All_Servers__c = true AND Account_s_Server_Name__c = :caseObj.Account_Server_Name__c AND (Expires_On__c >= : todaysDate OR Expires_On__c = NULL))  ];
                
             
        }
        else {
            return caseNews;
        }
    }

}

 

But me problem is that I don't know how to create the test method for this class.

 

Can anyone help understand how to do it?

 

Thanks

 

Tzuvy

Best Answer chosen by Admin (Salesforce Developers) 
Ritesh AswaneyRitesh Aswaney

Here's the gist of it

 

//The Record

Quote quote = [select id,opportunity.recordtypeid from quote where id = :q1.id];

  
//The Standard Controller - initialised with the record selected above 
 ApexPages.StandardController stc = new ApexPages.Standardcontroller(quote );
//The ControllerExtension, initialised with the standard controller
QuoteControllerExtension con = new QuotePdfSelectionController(stc);

 

 

All Answers

Ritesh AswaneyRitesh Aswaney

Here's the gist of it

 

//The Record

Quote quote = [select id,opportunity.recordtypeid from quote where id = :q1.id];

  
//The Standard Controller - initialised with the record selected above 
 ApexPages.StandardController stc = new ApexPages.Standardcontroller(quote );
//The ControllerExtension, initialised with the standard controller
QuoteControllerExtension con = new QuotePdfSelectionController(stc);

 

 

This was selected as the best answer
tzuvytzuvy

You are the man!