I want to create a custom logic that will copy the value of EmailMessage.Subject after the merge fields used in it get resolved.

I tried to do it on the after insert trigger on EmailMessage object. However, it turns out that the merge fields used in Subject field are not always resolved before after insert trigger execution. Is it a normal behavior? Should I use a flow for this case instead?

Lightning Email Template configuration: enter image description here

Here is how the email is send using Case.SendEmail action: enter image description here

Here is the received email (don't look at the yellow part as it is automatically appended to email subject in the after insert trigger, it's not a merge field that is used in the email): enter image description here

What I want to achieve? I want to save in some field on the Case object the latest email subject which is related to this case.

  • Can you show evidence that merge fields in Subject are not resolved at afterInsert but are resolved in the body? Are you sure the merge fields are properly formed?
    – cropredy
    Commented Jun 8, 2022 at 15:57
  • @cropredy I've just added photos. Merge fields are properly formed but it also turns out that these merge fields are not resolved also in the body.
    – Rechu
    Commented Jun 9, 2022 at 11:13
  • As I said, in the after insert trigger the email subject contains merge fields but they are not resolved yet, and the custom logic used there makes such an assignment: case.Customer_s_Latest_Email_Subject__c = emailThatFiredTrigger.Subject
    – Rechu
    Commented Jun 9, 2022 at 11:14
  • related: salesforceben.com/… - note statement that cross-object merge fields are not supported
    – cropredy
    Commented Jun 9, 2022 at 15:33
  • @cropredy where am I using the crossobject merge field?
    – Rechu
    Commented Jun 9, 2022 at 23:56

1 Answer 1


I've just found the solution for this scenario. I've created the Record-Triggered Flow on EmailMessage object that is ran everytime the EmailMessage is inserted and it's Status is equal to Sent. This is propably the best way to copy a value from a certain EmailMessage field in which the Merge Fields were used.

You must log in to answer this question.

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