You need to sign in to do that
Don't have an account?
Alex Kirby
StandardSetController test class help?
Hi all, I am really struggling with creating a testclass for the below:
I don't know why, I have tried many variations and still can't even get it to initialize the controller, just remains at 0%..
This is what I have so far and would of thought it would of at least shown something?
Help is always appreciated.
public with sharing class myCampaigns { public string selectedValue { get;set; } public List<SelectOption> statusOptions { get;set; } Public Integer noOfRecords{get; set;} Public Integer size{get;set;} public string inputText1{get;set;} string queryString; id uId; public ApexPages.StandardSetController setCon { get{ if(setCon == null){ uId = UserInfo.getUserID(); size = 30; if(selectedValue == 'All' || selectedValue == null){ queryString = 'Select id, Company, Name, Campaign_Code__c, Ownerid, LeadSource, Status, Opportunity_Start_Date__c, Opportunity_End_Date__c, Opportunity_Close_Date__c, Opportunity_Type__c From Lead where OwnerId = :uId'; }else{ queryString = 'Select id, Company, Name, Campaign_Code__c, Ownerid, LeadSource, Status, Opportunity_Start_Date__c, Opportunity_End_Date__c, Opportunity_Close_Date__c, Opportunity_Type__c From Lead where OwnerId = :uId and campaign_code__c =: selectedValue'; } setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString)); setCon.setPageSize(size); noOfRecords = setCon.getResultSize(); } return setCon; }set; } Public List<Lead> getLeads(){ List<Lead> leadList = new List<Lead>(); for(Lead l : (List<Lead>)setCon.getRecords()) leadList.add(L); return leadList; } public pageReference refresh() { setCon = null; getleads(); setCon.setPageNumber(1); return null; } public Boolean hasNext { get { return setCon.getHasNext(); } set; } public Boolean hasPrevious { get { return setCon.getHasPrevious(); } set; } public Integer pageNumber { get { return setCon.getPageNumber(); } set; } public void first() { setCon.first(); } public void last() { setCon.last(); } public void previous() { setCon.previous(); } public void next() { setCon.next(); } public void autoRun() { Schema.DescribeFieldResult statusFieldDescription = Lead.Campaign_code__c.getDescribe(); statusOptions = new list<SelectOption>(); for (Schema.Picklistentry picklistEntry : statusFieldDescription.getPicklistValues()) { statusOptions.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel())); } } }
I don't know why, I have tried many variations and still can't even get it to initialize the controller, just remains at 0%..
This is what I have so far and would of thought it would of at least shown something?
@isTest public class test_myCampaigns { static testMethod void myCampaignsTest(){ Lead l = new lead(); l.firstName = 'Test'; l.lastname = 'User'; l.Company = 'Test Company'; insert l; List <Lead> ld = [Select id from Lead]; Test.startTest(); Test.setCurrentPage(Page.myCampaigns); ApexPages.StandardSetController con = new ApexPages.StandardSetController(ld); myCampaigns ext = new myCampaigns(con); ext.getLeads(); Test.stopTest(); } }
Help is always appreciated.
ext.autoRun();
All Answers
public myCampaigns() {
}
Constructor not defined: [myCampaigns].<Constructor>(ApexPages.StandardSetController)
so after line#10 - just add this
public myCampaigns() {
}
the constructor is a method that doesn't return anything, that get's executed when the class is instanstated.
ext.autoRun();
Really appreciate your help on this!