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
subrat pandasubrat panda 

test class static testMethod void testFirst and static testMethod void testNext I am stuck can anyone help be on these methods.below my controller and test class

@isTest
public with sharing class CP_AccountTabExtTest{

    /*** Instance Variables ***/
    
    /*** Static Variables (Static) ***/
    private static User userCPU;
    private static User userCPM;
    private static List<User> users;
    private static Map<Integer, Account> mapParentAccounts;
    private static Account parentAccount;
    private static Map<Integer, Account> mapChildAccounts;
    private static Map<Integer, Contact> mapContacts;   
    
    /*** Constant Variables (Static Final) ***/
    
    /*** Public Instance Methods ***/   

    /*** Private Instance Methods ***/  
    
    /*** Static Methods ***/        
            
    static void GenerateData()
    {
        Profile objProfile=[Select Id from Profile where Name=: CP_TestDataFactory.profileAdmin];
        UserRole objRole=[select id from UserRole where PortalType='None' limit 1];
        User objUser = new User(alias = 'TestUser', 
                          email='CP_TestDFUser@PhilipsOC.test',
                          emailencodingkey='UTF-8', 
                          lastname='Testing', 
                          languagelocalekey='en_US',
                          localesidkey='en_US', 
                          UserRoleId=objRole.Id, 
                          profileid=objProfile.ID,
                          country='United States',
                          timezonesidkey='America/Los_Angeles', 
                          username='CP_TestDFUser@PhilipsOC.test',
                          isActive = true);
        User thisUser = [ select Id from User where Id = :UserInfo.getUserId()];
        System.runAs(thisUser) {
            insert objUser;
        }
        
        parentAccount = CP_TestDataFactory.GenerateParentAccount(objUser.Id);
        insert parentAccount;

        mapChildAccounts = CP_TestDataFactory.GenerateChildAccounts(250, parentAccount.Id);
        insert mapChildAccounts.values();
        
        mapContacts = CP_TestDataFactory.GenerateContacts(20, parentAccount.Id);
        insert mapContacts.values();
        
        Profile profileCPU = [select id from profile where name=: CP_TestDataFactory.profileCPU ];        
        userCPU = new User(alias = 'TestCPU', 
                          email='CP_TestDFUserCPU@PhilipsOC.test',
                          emailencodingkey='UTF-8', 
                          lastname='Testing', 
                          languagelocalekey='en_US',
                          localesidkey='en_US', 
                          profileid=profileCPU.ID,
                          contactId = mapContacts.get(1).Id,
                          country='United States',
                          timezonesidkey='America/Los_Angeles', 
                          username='CP_TestDFUserCPU@PhilipsOC.test',
                          isActive = true);     
        insert userCPU;     
        
        Profile profileCPM = [select id from profile where name=: CP_TestDataFactory.profileCPM ];        
        userCPM = new User(alias = 'TestCPM', 
                          email='CP_TestDFUserCPM@PhilipsOC.test',
                          emailencodingkey='UTF-8', 
                          lastname='Testing', 
                          languagelocalekey='en_US',
                          localesidkey='en_US', 
                          profileid=profileCPM.ID,
                          contactId = mapContacts.get(2).Id,
                          country='United States',
                          timezonesidkey='America/Los_Angeles', 
                          username='CP_TestDFUserCPM@PhilipsOC.test',
                          isActive = true);                 
        insert userCPM;         
        
        users = new List<User>();
        users.add(userCPU);
        users.add(userCPM);
    }
    static testMethod void testAll() {
           GenerateData();
           system.runAs(userCPU){
            PageReference pageref = Page.CP_AccountTab;
            Test.setCurrentPage(pageRef);
            ApexPages.StandardController controller = new ApexPages.StandardController(parentAccount);
            CP_AccountTabExt acExtController = new CP_AccountTabExt();
            String q = 'SELECT Name FROM ACCOUNT LIMIT 1';
            ApexPages.StandardSetController ACC = new ApexPages.StandardSetController(Database.getQueryLocator(q));
            List<SelectOption> ListViews = ACC.getListViewOptions();
            System.assertEquals(ListViews , acExtController.getAccountExistingViews());
            List<Account> accounts = [Select Id, Name, AccountNumber, ShippingStreet, ShippingCity, ShippingState, 
                                     ShippingCountry FROM Account ORDER BY Name ASC LIMIT 10000];
            System.assertEquals(accounts , acExtController.getAccounts());
            PageReference expectedPage = Page.CP_AccountDetail;
            String nextPage = acExtController.AccountDetailPage;
            System.assertEquals(expectedPage.getUrl(), nextPage); 
            acExtController.resetFilter();
            acExtController.prev();
            acExtController.next();
            acExtController.lastPage();
            acExtController.firstPage();
            
        }
		   system.runAs(userCPM){
            PageReference pageref = Page.CP_AccountTab;
            Test.setCurrentPage(pageRef);
            ApexPages.StandardController controller = new ApexPages.StandardController(parentAccount);
            CP_AccountTabExt acExtController = new CP_AccountTabExt();
            String q = 'SELECT Name FROM ACCOUNT LIMIT 1';
            ApexPages.StandardSetController ACC = new ApexPages.StandardSetController(Database.getQueryLocator(q));
            List<SelectOption> ListViews = ACC.getListViewOptions();
            System.assertEquals(ListViews , acExtController.getAccountExistingViews());
            List<Account> accounts = [Select Id, Name, AccountNumber, ShippingStreet, ShippingCity, ShippingState, 
                                     ShippingCountry FROM Account ORDER BY Name ASC LIMIT 10000];
            System.assertEquals(accounts , acExtController.getAccounts());
            PageReference expectedPage = Page.CP_AccountDetail;
            String nextPage = acExtController.AccountDetailPage;
            System.assertEquals(expectedPage.getUrl(), nextPage); 
            acExtController.resetFilter();
            acExtController.prev();
            acExtController.next();
            acExtController.lastPage();
            acExtController.firstPage();
            
        }	
    }
	static testMethod void testNext()}{
		GenerateData();
		system.runAs(userCPU){
            PageReference pageref = Page.CP_AccountTab;
            Test.setCurrentPage(pageRef);
            ApexPages.StandardController controller = new ApexPages.StandardController(parentAccount);
            CP_AccountTabExt acExtController = new CP_AccountTabExt();
		}
		system.runAs(userCPM){
            PageReference pageref = Page.CP_AccountTab;
            Test.setCurrentPage(pageRef);
            ApexPages.StandardController controller = new ApexPages.StandardController(parentAccount);
            CP_AccountTabExt acExtController = new CP_AccountTabExt();
		}
	
	}
	static testMethod void testPrev(){
		GenerateData();
		system.runAs(userCPU){
            PageReference pageref = Page.CP_AccountTab;
            Test.setCurrentPage(pageRef);
            ApexPages.StandardController controller = new ApexPages.StandardController(parentAccount);
            CP_AccountTabExt acExtController = new CP_AccountTabExt();
		}
		system.runAs(userCPM){
            PageReference pageref = Page.CP_AccountTab;
            Test.setCurrentPage(pageRef);
            ApexPages.StandardController controller = new ApexPages.StandardController(parentAccount);
            CP_AccountTabExt acExtController = new CP_AccountTabExt();
		}	
	
	}
    static testMethod void testLast(){
		GenerateData();
		system.runAs(userCPU){
            PageReference pageref = Page.CP_AccountTab;
            Test.setCurrentPage(pageRef);
            ApexPages.StandardController controller = new ApexPages.StandardController(parentAccount);
            CP_AccountTabExt acExtController = new CP_AccountTabExt();
		}
		system.runAs(userCPM){
            PageReference pageref = Page.CP_AccountTab;
            Test.setCurrentPage(pageRef);
            ApexPages.StandardController controller = new ApexPages.StandardController(parentAccount);
            CP_AccountTabExt acExtController = new CP_AccountTabExt();
		}
	
	}
	static testMethod void testFirst(){
		GenerateData();
		system.runAs(userCPU){
            PageReference pageref = Page.CP_AccountTab;
            Test.setCurrentPage(pageRef);
            ApexPages.StandardController controller = new ApexPages.StandardController(parentAccount);
            CP_AccountTabExt acExtController = new CP_AccountTabExt();
		}
		system.runAs(userCPM){
            PageReference pageref = Page.CP_AccountTab;
            Test.setCurrentPage(pageRef);
            ApexPages.StandardController controller = new ApexPages.StandardController(parentAccount);
            CP_AccountTabExt acExtController = new CP_AccountTabExt();
		}
	}
    }



public with sharing class CP_AccountTabExt {

  /*** Instance Variables ***/

  public String AccountFilterId { get; set;}
  private String query = 'Select Id, Name, AccountNumber, ShippingStreet, ShippingCity, ShippingState, ShippingCountry FROM Account ORDER BY Name ASC LIMIT 10000';    
    private Integer pageSize = 50;
  
    /*** Static Variables (Static) ***/
    
    /*** Constant Variables (Static Final) ***/    
      
    /*** Public Instance Methods ***/
  public CP_AccountTabExt(){}
  
  public String AccountDetailPage {
    get{
            if(AccountDetailPage == null){
        PageReference accountDetail = Page.CP_AccountDetail;
                return accountDetail.getURL();
      }
      return '';
    }
    Set;
  }  

  public ApexPages.StandardSetController AccountSetController {
        get{
            if(AccountSetController == null){
                AccountSetController = new ApexPages.StandardSetController(Database.getQueryLocator(query));
                AccountSetController.setPageSize(pageSize);

                // We have to set FilterId after Pagesize, else it will not work
                if(AccountFilterId != null)
                {
                  AccountSetController.setFilterId(AccountFilterId);
                }
            }
            return AccountSetController;
        }set;
    }

  public CP_AccountTabExt(ApexPages.StandardSetController ssc) {  }

    //Navigate to first Page
    public void firstPage()
    {
      AccountSetController.first();
    }

    //Navigate to last Page
    public void lastPage()
    {
      AccountSetController.last();
    }

    //Navigate to Next page
    public void next()
    {
      if(AccountSetController.getHasNext())
      {
        AccountSetController.next();
      }
    }

    //Navigate to Prev Page
    public void prev()
    {
      if(AccountSetController.getHasPrevious())
      {
        AccountSetController.previous();
      }
    }

    public List<Account> getAccounts()
    {
      return (List<Account>)AccountSetController.getRecords();
    }

    //Get all available list view for Account
    public SelectOption[] getAccountExistingViews(){
        return AccountSetController.getListViewOptions();
    }

    /**
    * Reset List View
    */
    public PageReference resetFilter()
    {
      AccountSetController = null;
        AccountSetController.setPageNumber(1);
        return null;
    }
   
    
}

This will be a big help as I am new to salesforce test class.
sweetzsweetz
Please tell the exact requirement. What is the error you are getting or what do you want it to be solved?
subrat pandasubrat panda
@sweetz I need to cover the test for                     public void firstPage() in  test class static testMethod void testFirst                                    and                                                                    public void next() in  test class  static testMethod void testNext                  
 in these method I need to check the page number for the result    This will be great help I am not able to initiate these test .