Set<String> conEmail = new set<String>();
List<String> UsrId = new List<String>();
Map<String, Id> UsrMap = new map<String, Id>();
for(Contact con : trigger.new ){
if(con.Email != null){
conEmail.add(con.Email);
}
}
List<User> userEmail = [SELECT Id, Name, Email FROM User WHERE Email In: conEmail];
for(User u : userEmail){
UsrMap.put(u.Email, u.Id);
}
for(Contact c : trigger.new){
if(UsrMap.containsKey(c.Email)){
c.OwnerId = UsrMap.get(c.Email);
}
}
Any ideas on why Owner is not being updated when I edit any contact record.
Thank you!2 answers
Hi Ramakant,I've already created a contact trigger and used before insert and before update.I tried updating the any fields from contact but the Owner field is not being updated. I also tried to remove
if(UsrMap.containsKey(c.Email))
still it does not work.