+ Start a Discussion
John GerhardJohn Gerhard 

email message and task relationship trigger

Hello,

When a task is created I update a lookup field with the whoID if the whoID is a contact that is. However, when someone sends an email it does not fire the trigger. Apparently this is because it creates an object called EmailMessage and not just a Task, well it also creates a Task. The problem that arises is that when the task is created it is being done by an internal flow so it does not fire my trigger. Okay no problem, then I need to move my trigger to fire when the EmailMessage is created. Then I run into the issue of I don't know how to query for the task created that is associated with this email message to update the fields on the task accordingly. Any help would be much appreciated.
Michael BrumleyMichael Brumley
No doubt you've figured this one out by now, but for anyone else searching for an answer: because the process is different here, the connection is as well. In this case the EmailMessage object has an ActivityId field pointing to the Task that was created. The rest is as you'd expect - in my case the Tasks being sought were generated by emails sent only from Opportunities, and the RelatedTo field had that Opp Id as expected. So your code design is a little different - start by getting the ActivityIds from the EmailMessage objects - but the rest is all the same.
Alex Skempris 18Alex Skempris 18
Thanks Michael. Your answer shed a lot of light to my situation as I had a similar problem with John.

Also for whoever stumbles on this thread, the ActivityId field is not accessible through the process builder. You'll to access it via Apex or via the Flow Builder.