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
streetstreet 

Testcase for below class?

public with sharing class Single_Invoice

 {

//Date d1;
Set<Id> tskNo = new Set<Id>();

public List<Opportunity> opp99{get;set;} 
public Opportunity userInputAppointment {get; set;}
public Opportunity o1 {get; set;}
 public Opportunity[] o ;
 public account[] acct ;


Set<Id> oppacctname = new Set<Id>();
 public Task[] t;
 //public invoice__c[] inv;
public Task[] tsk ;

public ApexPages.StandardSetController con {
get {
if(con == null) {

userInputAppointment = new Opportunity();
userInputAppointment.From_Date__c=Date.valueof(ApexPages.currentPage().getParameters().get('fromdate'));
userInputAppointment.To_Date__c=Date.valueof(ApexPages.currentPage().getParameters().get('todate'));

 tsk=[select id, description,whatid,ActivityDate, who.type,subject, whoid from task where Priority='Renewal' and ActivityDate>=:userInputAppointment.From_Date__c and  ActivityDate<=:userInputAppointment.To_Date__c]; 
 

for(Task aa: tsk)
 {
 tskNo.add(aa.whatid);
 } 


con = new ApexPages.StandardSetController(Database.getQueryLocator
([select id,name, Account.FirstName ,CloseDate, Director_ID__r.AccountId , Director_ID__r.FirstName ,
Director_ID__c,Amount,Account.Name, Account.Id ,Account.Director_ID__c,Start_Issue__c,Expire_Issue__c,
 Account.Salutation ,Invoice_Effort__c,Payment_Date__c,Refunded_Amount__c,
 Account.Mailing_Address__c,Account.Mailing_Ste_Apt__c,
Account.Mailing_State__c,Account.Mailing_City__c,Tax__c,Total__c,
Account.Mailing_Zip__c from Opportunity where id in:tskNo and recordType.id=:'012V0000000CgYl']));

// sets the number of records in each page set
con.setPageSize(1000);
}
return con;
}
set;
}

/*
public ApexPages.StandardSetController con {
get {
if(con == null) {

 opp99=(List<opportunity>)con3.getRecords();
 for(opportunity oo1: opp99)
 {
 oppacctname.add(oo1.AccountId );
 }
con = new ApexPages.StandardSetController(Database.getQueryLocator([Select id,Salutation,Verification_Date__c,FirstName ,PersonFirstNameLocal,Asset_Size__c,Mailing_Address__c,Mailing_Ste_Apt__c,Mailing_City__c,Mailing_Zip__c,Mailing_State__c,Director_ID__c,Bank_Status__c,Bill_To__c ,name,Bill_To__r.Id  FROM Account  where id in:oppacctname order by name  ]));
// sets the number of records in each page set
con.setPageSize(1000);
}
return con;
}
set;
}

public List<Account> getAccounts() 
{
return (List<Account>)con.getRecords();
}
*/

public List<opportunity> getopp() {
return (List<opportunity>)con.getRecords();
}



// returns the page number of the current page set
public Integer pageNumber {
get {
return con.getPageNumber();
}
set;
}


// returns the next page of records
public void next() {
con.next();
}


// indicates whether there are more records before the current page set.
public Boolean hasPrevious {
get {
return con.getHasPrevious();
}
set;
}

// returns the first page of records
public void first() {
con.first();
}

// returns the last page of records
public void last() {
con.last();
}
 
// returns the previous page of records
public void previous() {
con.previous();
}

 public PageReference deliverAsPDF() {
     
     
    PageReference pdf = new PageReference('/apex/Single_Invoice_VF');     
     // PageReference pdf =  Page.page;
        pdf.getParameters().put('p','p');
        return pdf;
  }

/*
public account[] getacct() 
{
return acct;
}

public Opportunity[] geto() 
{
return o;
}
public Task[] gett() 
{
return t;
}

public Task[] gettsk() 
{
return tsk;
}
*/

}

 

Best Answer chosen by Admin (Salesforce Developers) 
shruthishruthi

Hi

 

I believe, you wanted a test class for your class. If so, Try this testMethod:

 

static testMethod void testStandardSetController() {
    List<Opportunity> opps = new List<Opportunity>();
    ApexPages.StandardSetController con = new ApexPages.StandardSetController(opps);
    Single_Invoice SI = new Single_Invoice();
    List<Opportunity> oppsNew = SI.getopp();
    Integer pgNum = SI.pageNumber;
    SI.next();
    SI.previous();
    SI.first();
    SI.last();
    Boolean check = SI.hasPrevious;
}

Let me know if you face any issues with this! :)

All Answers

shruthishruthi

Hi

 

I believe, you wanted a test class for your class. If so, Try this testMethod:

 

static testMethod void testStandardSetController() {
    List<Opportunity> opps = new List<Opportunity>();
    ApexPages.StandardSetController con = new ApexPages.StandardSetController(opps);
    Single_Invoice SI = new Single_Invoice();
    List<Opportunity> oppsNew = SI.getopp();
    Integer pgNum = SI.pageNumber;
    SI.next();
    SI.previous();
    SI.first();
    SI.last();
    Boolean check = SI.hasPrevious;
}

Let me know if you face any issues with this! :)

This was selected as the best answer
streetstreet

Thanks Shruthi, its working :)