User Password Reset System

Select User S.No. Full Name Alias Username Role Profile
{! } {!user.Alias} {!user.UserName} {! } {! }

Page 1 of

Controller: public class dataTableCon { List users; public User userForReset {get;set;} public static System.ResetPasswordResult result; public System.PageReference pr; public dataTableCon(ApexPages.StandardController controller) { userForReset = (User) controller.getRecord(); } public Id objSelectedUserId {get;set;} public void handleuserCheckboxChange() { for(User objStudent: users) { if( == objSelectedUserId){ system.debug('-----This is the selected student record----'+objStudent); } } } public List getUsers() { if(users == null) users = [SELECT Name, Email, UserName, Alias, , , IsActive FROM User WHERE Username <> NULL]; return users; } public PageReference resetpass() { if (userForReset != NULL) { try{ users = [Select Email FROM User WHERE Id=: ]; Boolean email = true; for(User u : users) { result = System.resetPassword( , email); } } catch(Exception e) { } pr = Page.ResetPassword; } return pr; } } Can anyone please help by checking the code for errors?", "answerCount": 1, "upvoteCount": 0, "datePublished": "2020-04-05T16:51:43.000Z", "author": { "@type": "Person", "name": "Sachidanand Jha", "url": "https://trailblazers.salesforce.com/profileView?u=0053A00000FUhDiQAL", "affiliation": { "@type": "Organization", "name": "--" } }, "suggestedAnswer": [ { "@type": "Answer", "text": "Hello,    This VF page structure incorporates all requirements: data table, checkbox, reset button, count display, and pagination controls.    HTML                                                                     
              {!selectedUserCount} item(s) selected | Showing:               {!((pageNumber - 1) * pageSize) + 1}-{!MIN(pageNumber * pageSize, totalUserCount)} of {!totalUserCount} items         
                                                                                                                                                                                                                                                                                               
                                    Page: {!pageNumber}                               
                       
               
 
    E-ZPass Delaware", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54V00007T4Gc1SAF", "datePublished": "2025-11-03T11:29:44.000Z", "author": { "@type": "Person", "name": "ivy harriest", "url": "https://trailblazers.salesforce.com/profileView?u=005KX000003e33sYAA", "affiliation": { "@type": "Organization", "name": "--" } } } ] } }
Skip to main content
Hi Everyone,

I am a newbie to Salesforce and have been assigned the following task:

  1. Create a VF page where the list of users in the system is listed.

    1. Users should be able to select multiple Users and click on the ‘Reset password’ button. Upon click, Password reset mail should be sent to the selected users.
    2. Pagination should be available
    3. Number of user-selected should be displayed as available in Standard list view

I have create following VF page:

<apex:page standardController="User" extensions="dataTableCon" sidebar="false">

   <apex:form >

      <head>

         <title>Users - Detail Page</title>

         <apex:stylesheet value="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.2/css/bootstrap.min.css"/>

         <apex:stylesheet value="https://use.fontawesome.com/releases/v5.3.1/css/all.css"/>

         <apex:stylesheet value="{!$Resource.TicketingCSS}"/>

         <style class="INLINE_PEN_STYLESHEET_ID">

            .container {

            padding: 1.3rem 0rem;

            }

            h4 {

            margin: 1.3rem 0rem 0.6rem;

            }

            .table-image td, .table-image th {

            vertical-align: middle;

            }

            body {

            counter-reset: Count-Value;     

            }

            tr td:nth-child(2):after {

            counter-increment: Count-Value;   

            content: counter(Count-Value);

            }

            th, td {

            text-align:center;

            font-size:0.9rem;

            }

         </style>

         <script src="https://static.codepen.io/assets/editor/iframe/iframeConsoleRunner-dc0d50e60903d6825042d06159a8d5ac69a6c0e9bcef91e3380b17617061ce0f.js"></script>

         <script src="https://static.codepen.io/assets/editor/iframe/iframeRefreshCSS-e03f509ba0a671350b4b363ff105b2eb009850f34a2b4deaadaa63ed5d970b37.js"></script>

         <script src="https://static.codepen.io/assets/editor/iframe/iframeRuntimeErrors-29f059e28a3c6d3878960591ef98b1e303c1fe1935197dae7797c017a3ca1e82.js"></script>

      </head>

      <body>

         <p style="text-align:center;font-size:1.3rem;padding-top:10px;"> User Password Reset System </p>

         <div class="container">

            <div class="row">

               <div class="col-12">

                  <table class="table table-bordered">

                     <thead>

                        <tr>

                           <th scope="col">Select User</th>

                           <th scope="col">S.No.</th>

                           <th scope="col">Full Name</th>

                           <th scope="col">Alias</th>

                           <th scope="col">Username</th>

                           <th scope="col">Role</th>

                           <th scope="col">Profile</th>

                        </tr>

                     </thead>

                     <apex:repeat value="{!Users}" var="user">

                        <tbody>

                           <tr>

                              <td style="white-space:nowrap;">

                                 <div class="custom-control custom-checkbox">

                                    <apex:inputCheckbox value="{!userForReset}" styleClass="custom-control-input" id="customCheck1">

                                       <apex:actionSupport event="onclick"

                                          action="{!handleuserCheckboxChange}"

                                          reRender="ResultPanel">

                                          <apex:param id="user" name="userId" value="{!User.Id}"

                                             assignTo="{!objSelectedUserId}"/>

                                       </apex:actionSupport>

                                    </apex:inputCheckbox>

                                    <apex:outputLabel styleClass="custom-control-label" for="customCheck1"/>

                                 </div>

                              </td>

                              <td></td>

                              <td>{!user.Name}</td>

                              <td>{!user.Alias}</td>

                              <td>{!user.UserName}</td>

                              <td>{!user.UserRole.Name}</td>

                              <td>{!user.Profile.Name}</td>

                           </tr>

                        </tbody>

                     </apex:repeat>

                  </table>

               </div>

            </div>

         </div>

         <div align="center" draggable="false" >

            <apex:commandButton id="btn" action="{!resetpass}" value="Reset Password(s)" styleClass="submit-btn"/>

         </div>

         <p style="text-align:right;font-size:1rem;padding-bottom:10px;padding-right:100px;">Page 1 of </p>

         <script src="https://static.codepen.io/assets/common/stopExecutionOnTimeout-157cd5b220a5c80d4ff8e0e70ac069bffd87a61252088146915e8726e5d9f147.js"></script>

         <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

         <script type="text/javascript">

            $(function () {

                //Assign Click event to Button.

                $("⌗btn").click(function () {

                    var message = "Name Username Profile\n";

            

                    //Loop through all checked CheckBoxes in GridView.

                    $("⌗Table1 input[type=checkbox]:checked").each(function () {

                        var row = $(this).closest("tr")[0];

                        message += row.cells[3].innerHTML;

                        message += "   " + row.cells[4].innerHTML;

                        message += "   " + row.cells[6].innerHTML;

                        message += "\n";

                    });

            

                    //Display selected Row data in Alert Box.

                    alert(message);

                    return false;

                });

            });

         </script>      

      </body>

   </apex:form>

</apex:page>

Controller:

public class dataTableCon {

    List<User> users;

    public User userForReset {get;set;}

    public static System.ResetPasswordResult result;

    public System.PageReference pr;

      

    public dataTableCon(ApexPages.StandardController controller) {

        userForReset = (User) controller.getRecord();

    }

    

    public Id objSelectedUserId {get;set;}

    public void handleuserCheckboxChange() {

        for(User objStudent: users) {

            if(objStudent.Id == objSelectedUserId){

                system.debug('-----This is the selected student record----'+objStudent);

            }

        }

    }

    public List<User> getUsers() {

        if(users == null)

            users = [SELECT Name, Email, UserName, Alias, Profile.Name, UserRole.Name, IsActive FROM User WHERE Username <> NULL];

        return users; 

    }

    

    public PageReference resetpass() {

        if (userForReset != NULL) {

            try{

                users = [Select Email FROM User WHERE Id=:userForReset.Id];

                Boolean email = true;

                for(User u : users) {

                    result = System.resetPassword(u.Id, email);

                }

            }

            catch(Exception e) {

            }

                pr = Page.ResetPassword;

              

        }

        return pr;

    }

}

Can anyone please help by checking the code for errors?

1 answer
  1. Nov 3, 2025, 11:29 AM

    Hello, 

     

    This VF page structure incorporates all requirements: data table, checkbox, reset button, count display, and pagination controls. 

     

    HTML 

     

    <apex:page standardController="User" extensions="dataTableCon" sidebar="false"> 

        <apex:form > 

             

            <apex:pageMessages />  

             

            <apex:commandButton action="{!resetPasswords}" value="Reset Password" styleClass="btn btn-primary mb-3"/> 

             

            <div id="selectedCountDiv" style="font-weight: bold; margin-bottom: 10px;"> 

                {!selectedUserCount} item(s) selected | Showing:  

                {!((pageNumber - 1) * pageSize) + 1}-{!MIN(pageNumber * pageSize, totalUserCount)} of {!totalUserCount} items 

            </div> 

     

            <apex:pageBlock > 

                <apex:pageBlockTable value="{!wrappedUsers}" var="wUser" id="userTable"> 

                     

                    <apex:column headerValue="Select"> 

                        <apex:inputCheckbox value="{!wUser.isSelected}"> 

                            <apex:actionSupport event="onclick" reRender="selectedCountDiv"/>  

                        </apex:inputCheckbox> 

                    </apex:column> 

                     

                    <apex:column headerValue="Name" value="{!

    wUser.userRecord.Name

    }"/> 

                    <apex:column headerValue="Username" value="{!wUser.userRecord.Username}"/> 

                    <apex:column headerValue="Email" value="{!wUser.userRecord.Email}"/> 

                    <apex:column headerValue="Is Active" value="{!wUser.userRecord.IsActive}"/> 

                     

                </apex:pageBlockTable> 

     

                <div style="text-align: center; padding-top: 10px;"> 

                    <apex:commandButton action="{!previousPage}" value="Previous" rendered="{!hasPrevious}" reRender="userTable, selectedCountDiv" style="margin-right: 5px;"/> 

                    Page: {!pageNumber} 

                    <apex:commandButton action="{!nextPage}" value="Next" rendered="{!hasNext}" reRender="userTable, selectedCountDiv" style="margin-left: 5px;"/> 

                </div> 

                 

            </apex:pageBlock> 

             

        </apex:form> 

    </apex:page> 

     

    E-ZPass Delaware

0/9000