Skip to content

Instantly share code, notes, and snippets.

@townie
Last active October 9, 2017 19:55
Show Gist options
  • Save townie/31afa5b4be7ab4856381b1c508265fff to your computer and use it in GitHub Desktop.
Save townie/31afa5b4be7ab4856381b1c508265fff to your computer and use it in GitHub Desktop.
public class UserHistory_CreateUpdateFromUser {
static final String NEWUSERLIST = 'newUserList';
static final String LOBCHANNELLIST = 'lOBChannelList';
static final String ISACTIVELIST = 'isActiveList';
static final String UMANAGERLIST = 'uManagerList';
public static void findUser(List<User> newUsers, Map<Id,User> oldUsers, Boolean isInsert){
List<User> uList = new List<User>(); //Store user Ids matches logic
List<User> newUserList = new List<User>();
List<User> lOBChannelList = new List<User>();
List<User> isActiveList = new List<User>();
List<User> uManagerList = new List<User>();
Map<String, List<User>> reasonForUpdatingUser = new Map<String, List<User>>();
for(User u : newUsers){
if(isInsert && !String.isBlank(u.Channel__c)){
newUserList.add(u);
}
else if(!isInsert && (u.Channel__c != oldUsers.get(u.Id).Channel__c || u.LOB_Focus__c != oldUsers.get(u.Id).LOB_Focus__c)) {
lOBChannelList.add(u);
}
else if(!isInsert && u.IsActive != oldUsers.get(u.Id).IsActive){
isActiveList.add(u);
}
else if(!isInsert && u.ManagerId != oldUsers.get(u.Id).ManagerId){
uManagerList.add(u);
}
}
if(newUserList.size()>0){
reasonForUpdatingUser.put(NEWUSERLIST, newUserList));
}
if(lOBChannelList.size()>0){
reasonForUpdatingUser.put(LOBCHANNELLIST, lOBChannelList);
}
if(isActiveList.size()>0){
reasonForUpdatingUser.put(ISACTIVELIST, isActiveList);
}
if(uManagerList.size()>0){
reasonForUpdatingUser.put(UMANAGERLIST, uManagerList);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment