You need to sign in to do that
Don't have an account?
Taylor Ochs 5
Notify new Account Team Members Trigger
I need to write a trigger to nofity new members when they are added to an account team. My code doesn't seem to work, any help or ideas?
trigger Notify_Account_Team on Account (before insert, before update) {
for(Account acct : trigger.new){
List<Messaging.SingleEmailMessage> atm = new List<Messaging.SingleEmailMessage>();
EmailTemplate et=[Select id from EmailTemplate where
DeveloperName=:'Notify_Assign'];
List<AccountTeamMember> recips = new List<AccountTeamMember>(
[SELECT UserId
FROM AccountTeamMember
for(AccountTeamMember rid : recips){
mail.setTargetObjectId(rid.UserId);
mail.setSenderDisplayName('Salesforce System');
mail.setUseSignature(false);
mail.setBccSender(false);
mail.setSaveAsActivity(false);
mail.setTemplateId(et.Id);
}
}
atm.add(mail);
}
trigger Notify_Account_Team on Account (before insert, before update) {
for(Account acct : trigger.new){
List<Messaging.SingleEmailMessage> atm = new List<Messaging.SingleEmailMessage>();
EmailTemplate et=[Select id from EmailTemplate where
DeveloperName=:'Notify_Assign'];
List<AccountTeamMember> recips = new List<AccountTeamMember>(
[SELECT UserId
FROM AccountTeamMember
for(AccountTeamMember rid : recips){
mail.setTargetObjectId(rid.UserId);
mail.setSenderDisplayName('Salesforce System');
mail.setUseSignature(false);
mail.setBccSender(false);
mail.setSaveAsActivity(false);
mail.setTemplateId(et.Id);
}
}
atm.add(mail);
}
Modify your code as defiend below
Points to consider.
1. I have changed trigger to after insert and after update reason being you can't get Account id in before insert trigger.
2. EmailTemplate out of for loop now.
3. Singleemail message list out of loop now.
Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Thanks,
Karanraj
http://www.karanrajs.com
Line 11 Errors: Expecting a right parenthesis, found mail.setTargetObjectId(rid.UserId);
Line 14, Variable does not exist: mail
trigger Notify_Account_Team on Account (before insert, before update) {
List<Messaging.SingleEmailMessage> atm = new List<Messaging.SingleEmailMessage>();EmailTemplate et=[Select id from EmailTemplate where DeveloperName=:'Notify_Assign'];
for(Account acct : trigger.new){
for(AccountTeamMember rid : [SELECT UserId FROM AccountTeamMember]){
mail.setTargetObjectId(rid.UserId);
mail.setSenderDisplayName('Salesforce System');
mail.setUseSignature(false);
mail.setBccSender(false);
mail.setSaveAsActivity(false);
mail.setTemplateId(et.Id);
atm.add(mail);
}
}
Messaging.sendEmail(atm);
}
You need to define singel email message at that line. I am assuming that you are using my code because other code has some governer limit issues.
Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
SELECT UserId FROM AccountTeamMember where Accountid in : Trigger.newmap.keyset() returns more than 10 records. As
Total number of sendEmail methods allowed 10 in one transaction.
Then you may have to use Batch Apex to send mails as limit reset for each batch.
Regards,
I missed one line in my code.
put following line inside the for loop at the end.