Apex Trigger:
Map<String, Id> domains = new Map<String, Id>();
for(Contact con: Trigger.new) {
domains.put(con.Email.split('@').get(1), null);
}
for(Account acc: [SELECT Name FROM Account WHERE Name IN :domains.keySet()]) {
domains.put(acc.Name.toLowercase(), acc.Id);
}
for(Contact c: Trigger.new) {
if(domains.get(c.Email.split('@').get(1)) != null) {
c.AccountId = domains.get(c.Email.split('@').get(1));
}
}
}
No comments:
Post a Comment