Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

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 existing contact in Salesforce). 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 generated 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?

1 Answer

0 votes
by (32.1k points)

So, according to Salesforce, it is possible for you to associate the EmailMessage object to a contact. This can be done by populating the "BccIds" which are the contact or lead IDs.

Browse Categories

...