I'm working on a project where (already sent) emails should be saved to Salesforce and matched with the corresponding Salesforce contact.
Creating new Emails is rather straightforward. For example using the simple_salesforce python library my code looks like this:
from simple_salesforce import Salesforce
[…]
sf = Salesforce(instance_url=instance_url, session_id=session_id)
sf.EmailMessage.create(
{'FromAddress': '[email protected]',
'ToAddress': '[email protected]',
'Subject': 'Email: Fancy Subject',
'TextBody': 'lorem ipsum dolor sit amet',
'Status': 2
})
This successfully creates a new EmailMessage but the message is not matched to the contact (assuming [email protected] is an exisiting contact in Salesfored). This can be seen in numerous places in the Salesforce UI. For example:
- It is not part of the contact's activity history
- When looking at the Email Message details, the section “Sender and Recipients” is empty
When creating new emails using the Salesforce UI, the association is done correctly. Comparing my EmailMessage
objects from the ones generate by Salesforce there is one obvious difference: ActivityId
is not set for my objects.
When I'm trying to set ActivityId
I receive a Malformed Request Exception INSUFFICIENT_ACCESS_OR_READONLY
.
Is it somehow possible to create those associations using the API?