You need to sign in to do that
Don't have an account?
MsKnight
Summer '08 Bug - Outbound Email
Pre-Summer '08 we created code in Apex to send an email triggered on an update of a custom object. On Thrusday (6/5) and Friday (6/6) it was working fine. Since Monday all our testing shows that it updates, sends the email and then reverts back to previous values.
I have reviewed the Pre-Release notes and can't find anything that would have impacted our code. Please let me know if you have any suggestions!
Thanks
Code:
SendEmail.addSendEmail('Accounts Receivable','Roof Mounts In', p.Id); public static void addSendEmail(String role,String templateName,String whatId){ UserRole[] roleid = [SELECT Id FROM UserRole WHERE Name = :role]; User[] user = [SELECT Email FROM User WHERE UserRoleId = :roleid[0].Id]; Contact[] contact = [SELECT Id FROM contact WHERE Name = 'System User']; EmailTemplate[] template = [SELECT Id FROM EmailTemplate WHERE Name = :templateName]; Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {user[0].Email}; mail.setToAddresses(toAddresses); mail.setSaveAsActivity(false); mail.setTargetObjectId(contact[0].Id); mail.setWhatId(whatId); mail.setTemplateID(template[0].Id); // Send the email you have created. Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); }
I have reviewed the Pre-Release notes and can't find anything that would have impacted our code. Please let me know if you have any suggestions!
Thanks
Did you run it with Debug Log on so you could see if your update is getting rolled back due to a validation exception or some such thing?
Update - For testing sake we inserted the call to SendEmail into an entirely different set of code that was working perfectly. It behaved the same way - sent the email then reverted.
Message Edited by MsKnight on 06-11-2008 05:03 PM
You are either sending your email to an email address or to a salesforce ID (Contact, Lead or User) If you are using a template you have to use a TargerObjectId, and you can optionally use the whatId for the merging of the templates.
You can send emails with both a targetObjectId and Too, CC and BCC addesses. The merging will only be done for the contact you are passing in.
The code you have above should work, and if the code executes and are committed the email should be send.
If the email is being sent, it means the apex code is committed. Are you sure you don't have another process that would update or change the data after the apex code is committed? just wondering if there is something else going on here or if it is a bug
Message Edited by MsKnight on 06-12-2008 02:59 PM