
I am a newbie to Salesforce and have been assigned the following task:
- Create a VF page where the list of users in the system is listed.
- 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.
- Pagination should be available
- Number of user-selected should be displayed as available in Standard list view
</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?
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="{!
}"/>
<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