You need to sign in to do that
Don't have an account?

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
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.
Ayush
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,
Scott
We never found a workaround and just abandoned this effort. I hope you manage to figure something out!
Scott
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
objEMessage.ToAddress.equals('yourEmail'))
objEMessage.ToAddress.contains('yourEmail'))
objEMessage.CcAddress.contains('yourEmail'))
dont forget to check if CcAddress is nulll
if (objEMessage.CcAddress != null)
{
}