You need to sign in to do that
Don't have an account?
Activity Trigger not working
I have a trigger that should send an email to a specific email address if the task subject is troubleshooting and it is created by a specific user. But it doesnt work. any help would be greatly appreciated as I can not figure out this issue . The code is below.
trigger Trigger_SendPartsTechEmail on Task (before update) { List<Messaging.SingleEmailMessage> emailList=new List<Messaging.SingleEmailMessage>(); Map<Id, User> userMap = new Map<Id,User>([SELECT id FROM User WHERE Username IN('bpoliquin@cybexintl.com.cybextest','tghetti@cybexintl.com') AND isActive=True]); for(Task tsk : Trigger.New){ if(tsk.Subject=='Troubleshooting' && userMap.keySet().contains(tsk.createdById) ){ Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {'bpoliqui@aol.com'}; mail.setToAddresses(toAddresses); // Set the TO addresses mail.setSubject('A task owned by you has been updated'); // Set the subject String template = 'Hello {tsk.First_Name__c}, \nYour task has been modified. Here are the details - \n\n'; template+= 'Subject - {tsk.Subject}\n'; template+= 'Comments - {tsk.Activity_Comment__c}\n'; mail.setPlainTextBody (template); emailList.add(mail); } } Messaging.SendEmail(emailList); }
Please try below code and let me know if it helps you.
trigger Trigger_SendPartsTechEmail on Task (before update) {
List<Messaging.SingleEmailMessage> emailList=new List<Messaging.SingleEmailMessage>();
Map<Id, User> userMap = new Map<Id,User>([SELECT id FROM User WHERE Username IN('bpoliquin@cybexintl.com.cybextest','tghetti@cybexintl.com') AND isActive=True]);
for(Task tsk : Trigger.New){
if(Trigger.oldMap.get(tsk.id).Subject!=Trigger.newMap.get(tsk.id).Subject && tsk.Subject=='Troubleshooting' && userMap.containsKey(tsk.createdById) )
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'vivek.deshmane@gmail.com'};
mail.setToAddresses(toAddresses); // Set the TO addresses
mail.setSubject('A task owned by you has been updated'); // Set the subject
String template = 'Hello'+ tsk.First_Name__c+', \nYour task has been modified. Here are the details - \n\n';
template+= 'Subject -'+ tsk.Subject+'\n';
template+= 'Comments -'+ tsk.Activity_Comment__c+'\n';
mail.setPlainTextBody (template);
emailList.add(mail);
}
}
if(!emailList.isEmpty())
{
Messaging.SendEmail(emailList);
}
}
Please mark best anser if it's resovle your proble.
Regards,
-Vivek
vivek.deshmane@gmail.com
Please check if email relay setting is activited for perticular domain and your trying to send email on different.
To off email realy setting follow below step.
Got to setup ==>Email Relay Activation
Mark "Restrict Relay To Domains" uncheck then email will come if there is any domin check applied
Please let me know if it helps.
Best Regards,
-Vivek