1

We have enabled Email Drafts.

  • Prior to that, we already had validation rules in triggers (e.g that the 'To:' email address contains a valid email).
  • Before email drafts, these validation rules would fire when an email is sent.

We want to keep this functionality as is with email drafts, as opposed to firing the validation triggers when the draft is automatically saved.

The issue is that in the before trigger, the status of the email message is always set to 5 (meaning 'Draft'), even if the email is being sent and not saved.

  • (In the after trigger, the status is set to 3 ('Sent') when the email is being sent).

So my question is this: is there a way in the before trigger to see if the email has been saved as a draft as opposed to having been sent?

1
  • why not move the validation to the after trigger?
    – cropredy
    Nov 7, 2023 at 1:11

1 Answer 1

2

The only way I found to avoid triggering on drafts, but blocking sends, was to use an after save trigger. For some reason, the status is always wrong until the "after save" phase. Keep in mind that despite being "after", that's only a checkpoint.

Emails, like most other DML in Salesforce, are guaranteed not to send before the transaction completes, because they can always be rolled back if the transaction ultimately fails.

1
  • Thanks, saved the day for me yet again!
    – hamayoun
    Nov 15, 2023 at 22:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .