In my Current Project, I'm working on Role-Hierarchy automation, as part of testing, I wanted to do below 2 activities frequently:
1. Set User Role to blank.
2. Delete Role-Hierarchy.
Below class will address the above two activities:
public class CleanRoles { public static void cleanData() { List<User> updateUsersWithBlankRole = new List<User>(); for(User usr: [Select Id,UserRoleId From User where LastModifiedDate=Today]) { usr.UserRoleId = null; updateUsersWithBlankRole.add(usr); } Update updateUsersWithBlankRole; List<UserRole> DeleteRoles = [SELECT Id FROM UserRole where LastmodifiedDate=today order by LastModifiedDate Desc]; Delete DeleteRoles; } }
CleanRoles.cleanData();
Comments
Post a Comment