function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Scott KostojohnScott Kostojohn 

Struggling with “NULL” FromAddress in EmailMessage Before-Insert Trigger from Outlook Integration

I am trying to create a before-insert trigger on EmailMessage, so that when a user logs an email from the Outlook Integration, I can set the RelatedToId field based on the email sender (FromAddress).

What I am finding in my testing, however, is that both FromAddress and ValidatedFromAddress are NULL on insert! Perhaps due to how the Outlook Integration inserts email records - perhaps it follows up the insert with an update to populate the FromAddress field.

Unfortunately, I must put my logic in the before-insert - you are only allowed to set RelatedToId on insert.

(1) Do any of you have more details around the behavior of the Outlook Integration and the From fields that might help me?

(2) Can anyone see another solution to be able to programmatically set the RelatedToId for tracked emails, based on the sender, other than my approach of the before-insert trigger on EmailMessage?

I have considered moving my logic to an after insert, and trying to delete the original email and recreate it with all the right information, but that seems extreme and I am concerned about the impact the changing id (due to delete and create new) will have on the Outlook Integration.

Thanks to all for any help you can provide!
Scott Kostojohn
ayu sharma devayu sharma dev
Hello Scott,

Wanted to confirm one thing, do you see the contact or email related record on the Email Message related list? If so then you can query that record for Email Message and add it to the RelatedTo field. 

Mostly Outlook automatically attaches the record which has the same email as FROM so you can find that record. I have also done the similar thing recently. 

Let me know if you face any issues.

Scott KostojohnScott Kostojohn
Thanks for your reply, Ayush - but can you clarify?

What field on the EmailMessage object are you suggesting that I use to identify the sender?  As I mentioned, FromAddress and ValidatedFromAddress are both null.  There are no EmailMesageRelation records, because this is a before-insert for the EmailMessage, so the relation records can't exist yet.

Thanks gain,

Brian Good 13Brian Good 13
Scott - running into the same issue here.  Did you find anything out or have any workaround?  Thanks.
Brian Good 13Brian Good 13
What's interesting is I can query the EmailMessage record in Dev Console after the fact and the value is set correctly for the FromAddress.  However, when I run a debug log and look at the record details as my flow is running, the value is null.
Scott KostojohnScott Kostojohn
Hi Brian,
We never found a workaround and just abandoned this effort.  I hope you manage to figure something out!

Olavo AlexandrinoOlavo Alexandrino
There's one workaround for this...

1 check ValidatedFromAddress instead of FromAddress (it works at sending from Salesforce to outside)

if (objEMessage.ValidatedFromAddress.equals('yourEmail') || objEMessage.ValidatedFromAddress.contains('yourEmail'))
// do something

2 Check ToAddress and CcAddress at receiveing from external to Saleforce


dont forget to check if CcAddress is  nulll

if (objEMessage.CcAddress != null)