function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MsKnightMsKnight 

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.

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

werewolfwerewolf
Where in this code are you doing the update?  I don't see it.

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?
werewolfwerewolf
Oh, sorry, you mean that the update triggers this code.  I stand by my validation exception theory though -- if something in the trigger is causing an exception then it could cause the update to get rolled back.  If it happens after the code for sending the email, then the email will get sent, and then the changes will get rolled back -- just as you have observed.  Check those debug logs and see if something jumps out at you.
MsKnightMsKnight
I checked the debug log and there are no errors. When I take out the reference to the SendEmail class, everything works fine so it has to be something with the email class. I can see in the debug log that it has sent the messages but there are no errors after the send.

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
werewolfwerewolf
Well, that's very odd then.  Contact Support about it, perhaps that's a bug.
Rasmus MenckeRasmus Mencke
You can not specify both toAddresses and TargetIds.

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.


Rasmus MenckeRasmus Mencke
Disregard my last post, just tested this again.

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.
MsKnightMsKnight
The email sends. The problem is something about the email code is now causing the record to not update correctly. On Friday it worked fine. After the update it is broken.
Rasmus MenckeRasmus Mencke
What instance are you on? NA1, NA0 ?

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


MsKnightMsKnight
We are on NA1. We have checked mulitple times and there is nothing else happening that would cause the record to revert. Additionally, it worked without issue before the Summer '08 release.


Message Edited by MsKnight on 06-12-2008 02:59 PM
MsKnightMsKnight
After a month and a half of wrangling with Support, they released a fix for the bug.