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 

Help with custom controller extension class test method

Hi All,

 

I have a extension class in my visualforce page, in my class i build a list of records from my custom object when i initialize the controller. I need to limit this list in my test method to ensure i do not exceed the the governer limits, but i just cant seem to figure out how to do it. Please see my code below:

 

public class Recruitement_Dashboard_Controller1{

Public Transient List<Invite_Tracking__c> invitetracking;
    
    Public Recruitement_Dashboard_Controller1(ApexPages.StandardController controller) {
        invitetracking = [SELECT Id,Project__c,Member__c,
Contact__r.Exclude_from_Engagement_Index__c,Contact__r.Member_Invite_Ranking__c,
Contact__r.Region__c,Contact__r.FY_Quarter_Acceptance__c, Counter__c,Organization__r.Operating_Group__c,Organization__r.Client_Classification__c, Organization__r.Id, Organization__r.Global_FT_500_Position__c,
Organization__r.Revenues_Mil_Value__c FROM Invite_Tracking__c WHERE Project__c = 'COO Circle' AND Contact__r.Exclude_from_Engagement_Index__c = FALSE]; system.debug('invitetracking: '+invitetracking); } Public static testMethod void testRecruitement_Dashboard_Controller1() { List<Invite_Tracking__c> invitetracking; PageReference pageref = Page.Recruitment_Dashboard; Test.setCurrentPage(pageRef); Account org = new Account(Name='test'); insert org; Contact con =new Contact (LastName = 'test', AccountId=org.Id, Exclude_from_Engagement_Index__c = FALSE,
Project__c = 'COO Circle'); insert con; Invite_Tracking__c invitetrackinginsert = new Invite_Tracking__c(Contact__c = Con.Id, Organization__c = org.Id ); insert invitetrackinginsert; ApexPages.standardController controller =
new ApexPages.standardController(invitetrackinginsert); Recruitement_Dashboard_Controller1 recruitement =
new Recruitement_Dashboard_Controller1(controller); /*invitetracking = [SELECT Id,Project__c,Member__c,Contact__r.Exclude_from_Engagement_Index__c, Contact__r.Member_Invite_Ranking__c,Contact__r.Region__c,Contact__r.FY_Quarter_Acceptance__c,Counter__c, Organization__r.Operating_Group__c, Organization__r.Client_Classification__c, Organization__r.Id, Organization__r.Global_FT_500_Position__c, Organization__r.Revenues_Mil_Value__c FROM Invite_Tracking__c WHERE Project__c = 'COO Circle' AND Contact__r.Exclude_from_Engagement_Index__c = FALSE limit 100];*/

 I cant seem to figure out how to get the limited list assignment correct in my test method.

 

Any suggestions???

 

Thanks,

 

Rudi


bob_buzzardbob_buzzard

So I guess the problem is that you have too much real data present.

 

There's a couple of ways to handle this:

 

(1) Create all data for your unit test inside the unit test - this relies on you being able to restrict your query based on the freshly created data, which may not be possible.  This is the recommended way.

(2) Have a static Boolean testMode variable, that is false by default.  Then set this to true prior to constructing your extension controller.  Finally, have you query builder add " limit 100" when testMode is true.