+ Start a Discussion

I'm so frustrated - please help - Email trigger testing


I'm extremely frustrated at the moment and I'm hoping someone can help me.  I have posted a few times now in the forums and while people have offered hints/suggestions, no one seems to have an answer for my question.  My question is this:

I am trying to write a trigger that will send an email when a contact is deleted from an organization.  The code works perfectly in the sandbox environment.  However, when I try to deploy to the production side, Salesforce won't allow the deployment because it says that the code has not been tested enough.  


Herein lies my problem:  HOW DO I TEST CODE FOR EMAILS???  I have tried everything - I have read the user guides, been through the forums, and even contacted Salesforce directly (they were no help whatsoever).  Every other piece of code tests fine, but the tester refuses to look at code dealing with email.  Here is my code:



trigger contactDelete on Contact (before delete) { try { for (Contact c : Trigger.old) { Account acct = [SELECT Name, Id FROM Account WHERE Id = :c.AccountID]; Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] tAddresses = new String[] {'tim.andrews@evariant.com'}; mail.setToAddresses(tAddresses); mail.setReplyTo('support@evariant.com'); mail.setSenderDisplayName('Salesforce Support'); mail.setSubject('Contact Deleted: ' + c.FirstName + ' ' + c.LastName); mail.setUseSignature(false); mail.setPlainTextBody( 'Contact ' + c.FirstName + ' ' + c.LastName + ' has been deleted!\n' + 'Contact ID: ' + c.Id + '\n\n' + 'Contact Organization: ' + acct.Name + '\n\n' + 'Organization ID: ' + acct.Id ); Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } } catch (NullPointerException e) { System.debug('Exception Thrown!'); Exception e1 = e; }}


As I said, the lines dealing with email code refuse to even be tested.  Any ideas/help would be greatly appreciated!




What does your test code look like?

Was this ever resolved?