0

I created a draft EmailMessage (status = 5) and linked it to a case. After all approvals are done, the message should be sent. However, I cannot find a way to do this. The standard Messaging.sendEmail method can send instances of the SingleEmailMessage or MassEmailMessage classes, but not a record of the EmailMessage object.

How to send a prepared draft EmailMessage and make sure that is remains linked to the Case instance with the new status (sent = 3)?

2
  • 1
    I'll be surprised if you can do this. EmailMessage is tightly wired to EmailToCase. You can see from the SObject doc that EmailMessage.Status can't be updated by the API (or by inference, Apex). Why not rebuild the draft email using SingleEmailMessage, send through Apex, delete the draft, and then insert a new EmailMessage with status Sent?
    – cropredy
    Mar 14 '14 at 17:29
  • I just did some testing and you can insert new EmailMessage objects. Didn't try updating any status, but it was interesting that it preventing me creating emails with status = 5 (assuming thats draft). Status=3 actually worked no problem.
    – NSjonas
    May 28 '15 at 20:10
2

The only way to do this is to:

  1. Create and send an instance of SingleEmailMessage populating it with fields of the draft.
  2. Create a new EmailMessage with the Sent status (= 3) with fields copied from the draft.
  3. Delete the old draft Emailmessage.
2
  • Think you could post your example code for how you did this? It would be really appreciated!
    – NSjonas
    May 28 '15 at 7:31
  • I am guessing that the main problem for you is creating a draft email. To be able to create a draft EmailMessage (status = 5), you need to enable the Setup -> Customize -> Settings -> Enable Email Drafts option. Jun 3 '15 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.