In continuation with this question:
I send a SingleApexMessage from apex code and want to associate it with a Lead so that a record of Activity History is created when this email is sent. For this, I am doing a
setTargetObjectId with Lead Id on this email before sending it. This creates an activity history on Lead.
Requirement: 2 custom fields on this activity history should be populated as well.
Here is what I tried:
Approach 1: Query for EmailMessage and update it. Problem here is how to fetch EmailMessage related to Lead, which field identifies this?
Approach 2: Do not do a
setTargetObjectId, instead create a
new EmailMessageand populate it with all custom and standard fields. Problem here is how to relate this with Lead?