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
EagerToLearnEagerToLearn 

Issue with test class: List out of bound

Hi,
I am having issues with a test class that used to work but after making many changes to the VF and Controller and getting those to work, I started getting the following error "class contructor not defined: [ApexPages.StandardController].<Constructor>() at 14 and then I added the following to the controller: 

    public SandboxRefreshUtilPwdChgController() {

    }  
   
Then I now get the list out of bound error.

THIS IS A PORTION OF THE CONTROLLER:
public with sharing class SandboxRefreshUtilPwdChgController {
    
    //list for holding the wrapped users and Integers to be displayed on the page 
    public List<userWrapper> wrappedObjects = new List<userWrapper>();         
    public List<User> userList;    
    public Map<Id, User> compareMap = new Map<Id, User>();
    
    
    // Constructors 1
    public SandboxRefreshUtilPwdChgController() {

    }  
   
    // Constructor 2
    public SandboxRefreshUtilPwdChgController(ApexPages.StandardController ex) {    
        System.debug('constructor');
        List<User> userList = getUsers();
        Integer i = 0; //integer for tracking the row counter value we want to pass back in the wrapper
        for ( user u : userList ) { //start looping through users
            i++; //increment the integer
            userWrapper wrappedObject = new userWrapper(u, i); //wrap the user with the Integer, which calls the userWrapper class below
            wrappedObjects.add(wrappedObject); //add the wrapper object to our list
        }    
    }    

....
....

AND THIS IS THE TEST CLASS:
@isTest
private class SandboxRefreshUtilPwdChgController_Test {
    @testSetup static void setupTestData() {      
        createUserRecords();
    }
    
    private static testMethod void PasswordChangeSucccesTest() {
        List<User> userList = [SELECT id, Email FROM User WHERE CreatedDate = TODAY];
        System.debug('TEST: userList.size(): ' + userList.size());
        
        Test.startTest();
            PageReference pageRef = Page.SandboxRefreshUtilPwdChg;
            Test.setCurrentPage(pageRef);
            SandboxRefreshUtilPwdChgController con = new SandboxRefreshUtilPwdChgController();            //1st error before change
            con.getWrappedObjects()[0].pwd = 'PwT5Srefresh!';          //current error after adding a blank constructor
            con.UpdatePasswords(); 
            System.assertEquals('Yes', con.getWrappedObjects()[0].successfulChange, 'Password Change failed!');
        Test.stopTest();
    }
    


Appreciate your support
Tom
 
Sandeep YadavSandeep Yadav
Hi,
list out of bound error means your query does not return any record.
You are not retrieving pwd field in your query.
Change your query with this--
List<User> userList = [SELECT id, Email,pwd FROM User WHERE CreatedDate = TODAY];