+ Start a Discussion
AKallAKall 

What are the required parameters for a Single Email Message?

Can anybody tell me what the required parameters for a Single Email Message are (Messaging.SingleEmailMessage)? I am trying to debug a trigger that sends one that we have created that uses a Visual Force email template. My test method continuously fails because according to the debug log a Parameter value is null.
crmexpertcrmexpert

the fields(with their IDs) that are mandatory:

 

1. TO field ---------- p2

2. Subject field ----- p6

 

hope that helps..

BrianWKBrianWK

I was having this same issue last week.

 

The required fields depends on what you're using. For example, if you're using a TemplateID you need to specify a TargetObjectID.

 

If you're not using a templateID - you should have either or both HTML or PlainText body defined. You can also use a "To" address or you can use a Who ID (sending to a contact).

 

The frustrating thing with the Parameter is null is the debugs logs won't help you out. I've added a system.debug to show me the whole MAIL object - and there were no required parameters that were null. I ended up closing Ecclipse and rebooting. When I opened it back up and ran the same unit test I had - everything passed.

 

So before you stress yourself out and spend about 6 hours trying to debug a failing unit test with an e-mail try the following:

 

1. Assuming your singleEmailMessage is called "mail" try System.Debug ('This is the mail object: " +Mail) then run your test and go through your debug log looking for system.emailexception - and look at the mail object. It'll spit out everything and what's Null, empty () or populated. That should help.

 

2. If the debug mail looks ok - Close ecclipse - or whatever program you're using - and Reboot your computer

 

3. If that fails, try to deploy your unit test, trigger/class etc to a different Sandbox