6

I have a before insert trigger on EmailMessage object and here is the trigger:

It just adds some extra content to the end of the email content.

trigger EmailMessageTrigger on EmailMessage (before insert) {
    if (trigger.isBefore && trigger.insert){
        for (EmailMessage eMsg: newList){
            eMsg.TextBody = eMsg.TextBody + '\n \n ******************* : ';
        }
    }
}

and this is how it looks in salesforce when I send email by clicking on the 'send Email' button:

enter image description here

but the actual email sent out doesn't have the extra content that I added in the trigger:

Below is the screenshot of the 'Show original' in my gmail:

enter image description here

What am I missing here?

How come in salesforce it shows that the email sent out has the extra characters appended in the trigger but the actual email received doesn't have that content?

Is it because of the order of execution??

1
  • Why is this downvoted??
    – javanoob
    May 22, 2016 at 0:43

1 Answer 1

12

The content of the email sent out to the recipient can't be changed by changing the content in EmailMessage record. When you do the change in before insert, it modifies only the EmailMessage record and the original message sent out is not altered.

For the inbound message, the content customer sent will be received as is to our outlook/gmail inbox. But the EmailMessage record can be altered to store additional characters in it body.

If you really want to change the content, add a template or modify the body before sending out the email.

Hope it helps.

2
  • Is this to say that the EmailMessage record does NOT finish it's beforeInsert/Update triggers before sending the email? Feb 6, 2020 at 16:20
  • the above is true also for the EmailMessage.Subject
    – cropredy
    Nov 23, 2020 at 22:22

You must log in to answer this question.

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