You need to sign in to do that
Don't have an account?
Chelsea Lukowski
Email task to multiple Account Team Members
I am trying to create a trigger that sends an email to multiple Account Team Memebers based on their account team member role when a Call is Logged. The email would only send to those users that have the account team Role of Ag Manager, Tyre Manager, Track Manager, or Wheel Manager. I sends when I log a call, but only to one user and not all users listed in the account team section with the matching roles.
trigger TaskEmailAccountTeam on Task (after insert, after update) { List<Messaging.SingleEmailMessage> atm = new List<Messaging.SingleEmailMessage>(); EmailTemplate et=[Select id from EmailTemplate where DeveloperName=:'Log_a_Call']; for(task t : Trigger.new){ Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); if(t.Email_Account_Team__c == True) { List<AccountTeamMember> recips = new List<AccountTeamMember>( [SELECT UserId,TeamMemberRole FROM AccountTeamMember WHERE AccountId = :t.AccountId AND (TeamMemberRole ='Ag Manager' OR TeamMemberRole ='Tyre Manager' OR TeamMemberRole ='Track Manager' OR TeamMemberRole ='Wheel Manager')]); recips.addAll(recips); for(AccountTeamMember rid : recips){ mail.setTargetObjectId(rid.UserId); mail.setUseSignature(true); mail.setBccSender(false); mail.setSaveAsActivity(false); mail.setTemplateId(et.Id); } } atm.add(mail); } Messaging.sendEmail(atm); }
@Karanraj
Here is the updated code. You have to add the list of mail inside the for loop statement. Else it will include only the last mail message in the list