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
Waqar Hussain SFWaqar Hussain SF 

How to write test class for my accountPagination class.

public with sharing class AccountPagination {
    private final Account acct;  

    // The constructor passes in the standard controller defined
    // in the markup below
            public AccountPagination(ApexPages.StandardSetController controller) {
        this.acct = (Account)controller.getRecord(); 
    }    
    
    public ApexPages.StandardSetController accountRecords {
        get {
            if(accountRecords == null) {
                accountRecords = new ApexPages.StandardSetController(
                    Database.getQueryLocator([SELECT Name FROM Account WHERE Id NOT IN 
                        (SELECT AccountId FROM Opportunity WHERE IsClosed = true)]));
            }
            return accountRecords;
        }
        private set;
    }
    public List<Account> getAccountPagination() {
         return (List<Account>) accountRecords.getRecords();
    }  
}
Best Answer chosen by Waqar Hussain SF
rajesh k 10rajesh k 10
Hi,
              Find below code 100% code coverage

@isTest
public class TestAccountPagination {
    public static testmethod void unittest()
    {
        List<Account> acclist=new List<Account>();
        for(Integer i=1;i<15;i++)
        {
            Account acc=new Account();
            acc.Name='My account';
            acc.phone='1234567';
            //add mandatory fields
            acclist.add(acc);
            
        }
        insert acclist;
        
        ApexPages.StandardSetController sc = new ApexPages.StandardSetController(acclist);
        sc.setSelected(acclist);

        AccountPagination scExt = new AccountPagination(sc);
        scExt.getAccountPagination();
            
    }
 

}

this is currect make it as best answer....

thanks,
rajesh..