You need to sign in to do that
Don't have an account?
Trigger to assign Event WhoId field not working
I am unable to assign the WhoId field to a contact ID in the trigger below. I do actually get the ID from the query statement in trigger. I have verified that already, but when I assigned it to WhoId for the event that's firing the trigger, nothing seems to happen. Any clues?
trigger ContactList on Event (before insert) {
List<string> elist;
LIST<Contact> contacts;
EventRelation er;
string qemail;
String input;
String[] splitInput;
for(Event e: Trigger.new) {
// Create a list of emails by using ';' as delimeter
input = e.Description;
if(input != null){
input = input.replace('\r',' ');
input = input.replace('\n',' ');
input = input.replace('\t',' ');
splitInput = input.split(' ');
}
elist = new List<String>( splitInput );
// Iterate through the list if not empty
if (!elist.isEmpty())
for(Integer j = 0; j < elist.size(); j++){
if(elist[j].contains('@') && elist[j].contains('.')){
qemail = elist[j].trim();
contacts = null;
// Query for contact name and contact ID, associated with recipient email address
contacts = new List<Contact>([Select ID,Email,Name from Contact where Email = :qemail]);
if(!contacts.isEmpty())
e.WhoId = contacts[0].ID;
}
}
}
}
Diehard,
First and foremost ,you should be running query inside your For loop,that is not recommended at all.I ahve modified the code.Please find below the uodated one:-
Another thing to note is whether you have shared activities enabled in your org.Please check that.That might be the root cause.