You need to sign in to do that
Don't have an account?
Chinna Sfdc
Task Emails:
Hi Team,
Opprtunity owners and thier managers should get an email after task completion.we are trying to below trigger code, logic is working only for opportunity owner getting completion mail but not for their managers ,we need to send opoortunity owner and their managers also .Please help us for this.
Bit of code:
trigger TaskEmailNotification on Task (after update ){
Set<Id> ownerIds = new Set<Id>();
for(Task tsk: Trigger.New){
if(tsk.Status=='Completed'&&Trigger.oldMap.get(tsk.Id).Status != 'Completed' && tsk.OwnerId != tsk.CreatedById ){
ownerIds.add(tsk.CreatedById);
}
}
Map<Id,User> userMap = new Map<Id,User>([select Name,Email from User where Id in :ownerIds]);
List<Messaging.SingleEmailMessage> emailMsglist=new List<Messaging.SingleEmailMessage>();
for(Task tsk : Trigger.New){
if(tsk.Status=='Completed' && Trigger.oldMap.get(tsk.Id).Status != 'Completed' && tsk.OwnerId != tsk.CreatedById){
User theUser = userMap.get(tsk.CreatedById);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {theUser.Email};
Thanks in Advance
Opprtunity owners and thier managers should get an email after task completion.we are trying to below trigger code, logic is working only for opportunity owner getting completion mail but not for their managers ,we need to send opoortunity owner and their managers also .Please help us for this.
Bit of code:
trigger TaskEmailNotification on Task (after update ){
Set<Id> ownerIds = new Set<Id>();
for(Task tsk: Trigger.New){
if(tsk.Status=='Completed'&&Trigger.oldMap.get(tsk.Id).Status != 'Completed' && tsk.OwnerId != tsk.CreatedById ){
ownerIds.add(tsk.CreatedById);
}
}
Map<Id,User> userMap = new Map<Id,User>([select Name,Email from User where Id in :ownerIds]);
List<Messaging.SingleEmailMessage> emailMsglist=new List<Messaging.SingleEmailMessage>();
for(Task tsk : Trigger.New){
if(tsk.Status=='Completed' && Trigger.oldMap.get(tsk.Id).Status != 'Completed' && tsk.OwnerId != tsk.CreatedById){
User theUser = userMap.get(tsk.CreatedById);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {theUser.Email};
Thanks in Advance
Please see below article which has the code to send an email to opportunity manager.You can make changes according to your requirement.
Trigger to send email to Opportunity owner's manager
Knowledge Article Number000181297
DescriptionThis article will provide the trigger to send an email to Opportunity owner's manager when the stage is "Closed Won". Currently, the trigger will work on clicking the "Clone" button on Opportunity record as per the requirement. It can be modified for other requirements changing the after insert or after update conditions.
Resolution:
Hope this helps you!
Please accept my solution as Best Answer if my reply was helpful. It will make it available for other as the proper solution. If you felt I went above and beyond, you can give me kudos.
Thanks and Regards
Sandhya