I am beginner in salesforce APEX coding. Currently I am trying to make a scheduler for my org where i want to update my ManagerID form the UserRole.
In my testing ORG this code is showing 93% of code coverage but when I want to deploy in the production, The code coverage is only 67%. Can anybody help me with the below code:
AstroUpdateManagerID
public class AstroUpdateManagerID{
public List<UserRole> UserRoleList1(){
List<UserRole> userRole = new List<UserRole>();
userRole= [select Id, Name, ParentRoleId from UserRole];
return userRole;
}
List <UserRole> role =UserRoleList1();
Map <Id, User> userParentMap = new Map <Id, User>();
Map <Id, UserRole> userRoleMap = new Map <Id, UserRole>();
public User HandleParentNull(UserRole userroleobj){
User userobj = new User();
userobj = userParentMap.get(userroleobj.ParentRoleId);
if(userobj == null ){
UserRole userRole2 = userRoleMap.get(userroleobj.ParentRoleId);
userobj = HandleParentNull(userRole2);
}
return userobj;
}
public String get_Manager_ID_Where_Partner_Owner_Is_NA(User u){
UserRole userRoleOBJ = userRoleMap.get(u.UserRoleId);
return HandleParentNull(userRoleOBJ).Id;
}
public List<User> UserIdentification(List<User> user){
List<User> AllUserList = new List<User>();
//Find User role by UserRole.Id
for(UserRole ur: role){
userRoleMap.put(ur.Id, ur);
}
//Find user by User.UserRoleId
for(User userparent: user){
userParentMap.put(userparent.UserRoleId, userparent);
}
for (User u: user){
if(u.Partner_User_Owner__c != 'NA' && u.UserRole.Name != 'Director of Sales' && u.Profile.Name != 'System Administrator'){
u.ManagerId = u.Partner_User_Owner__c;
AllUserList.add(u);
}else if(u.UserRole.Name != 'Director of Sales' && u.Profile.Name != 'System Administrator'){
u.ManagerId = get_Manager_ID_Where_Partner_Owner_Is_NA(u);
AllUserList.add(u);
}
}
return AllUserList;
}
}
AstroUpdateManagerIdBatch
global class AstroUpdateManagerIdBatch implements Schedulable{
global void execute(SchedulableContext sc) {
AstroUpdateManagerID umi = new AstroUpdateManagerID();
List<User > AllUser = new List<User >();
AllUser = [select Id, Name, UserName, ManagerId, UserRoleId, UserRole.Name, isActive, Partner_User_Owner__c, Profile.Name from User Where IsActive=true and UserRole.Name!=null];
update umi.UserIdentification(AllUser);
}
}
TestDataAccessClassManagerID
@isTest(SeeAllData=true)
public class TestDataAccessClassManagerID {
@isTest
static void myTestMethodForManager() {
List <User> AllUserList = [select Id, Name, UserName, ManagerId, UserRoleId, UserRole.Name, isActive, Partner_User_Owner__c, Profile.Name from User Where IsActive=true and UserRole.Name!=null];
AstroUpdateManagerID umi = new AstroUpdateManagerID();
List <User> userListUpdate = umi.UserIdentification(AllUserList);
AstroUpdateManagerIdBatch bupdate = new AstroUpdateManagerIdBatch ();
String sch = '0 0 23 * * ?';
Test.startTest();
system.schedule('Test Territory Check', sch, bupdate );
update userListUpdate;
Test.stopTest();
}
}
Aucun commentaire:
Enregistrer un commentaire