Skip to main content
Question

Salesforce API calls

  • July 7, 2026
  • 3 replies
  • 75 views

Forum|alt.badge.img

Hello Community,

Customer is using the Rest API package from the Bot to perform certain salesforce API calls related to email communication of salesforce. These API's are supposed to append to existing email records in salesforce, 

The API's itself work fine and bot is not experiencing any issue but the problem is that every time it created a new email record instead of appending to existing email chain. Any suggestions on the best APIs that can be used in this situation?

3 replies

Aaron.Gleason
Automation Anywhere Team
Forum|alt.badge.img+6
  • Automation Anywhere Team
  • July 8, 2026

 

Key question… Is the bot:

  • Creating records in the EmailMessage object only?

  • Sending actual emails through Salesforce?

  • Working against Cases (Email-to-Case) or against some custom object?

That distinction determines whether Lightning Threading, Email-to-Case, or email-header threading is the correct solution.

If the REST API call is successfully creating EmailMessage records, but each message appears as a new email record/conversation instead of being threaded into an existing chain, the issue is usually not the API itself, but rather the email threading metadata being sent to Salesforce. [help.salesforce.com], [simplysfdc.com]

 

What's likely happening

When you create an EmailMessage through the API, Salesforce treats it as a new email unless it can correlate it to an existing thread using:

Simply inserting a new EmailMessage record with the same Case, Contact, or Account does not automatically make it part of the same email conversation. [simplysfdc.com], [developer....sforce.com]

 

Recommended approaches

Option 1 (Best for Case-related email conversations)

Use Email-to-Case with Lightning Threading.

Salesforce's current recommendation is to use the newer Lightning Threading model, where outbound emails include a threading token and inbound replies are matched back to the original Case. [help.salesforce.com], [salesforcetime.com]

This is generally the most reliable solution if the emails belong to a Case lifecycle.

 

Option 2

Populate the email header fields correctly when creating the email:

{
"MessageIdentifier": "<new-message-id@domain.com>",
"ReplyToEmailMessageId": "02sXXXXXXXXXXXX"
}
or preserve the original:
  • In-Reply-To

  • References

headers from the previous email chain. Salesforce uses these values for header-based threading. [simplysfdc.com]

 

Option 3

If the bot is sending outbound emails and later appending updates, consider using:

  • EmailMessageRelation

  • ParentId (Case)

  • Existing EmailMessage references

rather than creating standalone EmailMessage records each time. However, this associates records—it does not by itself create true email threading. [developer....sforce.com]

 

APIs I'd recommend

  1. Messaging / Email-to-Case APIs with Lightning Threading (preferred) [help.salesforce.com], [salesforcetime.com]

  2. EmailMessage REST/SOAP API with proper header values (In-Reply-To, References, Message-ID) [simplysfdc.com]

  3. If Service Cloud is involved, use the Case + EmailMessage model rather than directly creating unrelated email records. [developer....sforce.com], [help.salesforce.com]


  • Cadet | Tier 2
  • July 8, 2026

Hello ​@Aaron.Gleason ,

Thank you for providing those details.

We have applied this approach already, but unfortunately, we are finding that the emails are not threading as expected when sent out. And its working through email to case in salesforce there is no custom piece in place.

 


Aaron.Gleason
Automation Anywhere Team
Forum|alt.badge.img+6
  • Automation Anywhere Team
  • July 8, 2026

@jash.mehta Thank you for your response. I believe your question is more Salesforce related than Automation Anywhere related. I haven’t done any Salesforce coding in over 10 years, so I had to rely on AI for assistance.

I didn’t flag this topic for removal because there might be some people in our forum that know Salesforce well enough to answer the question. Honestly, this question probably should be raised in a Salesforce forum for best visibility and more likely someone who has had this issue before and can answer your question.

https://www.salesforce.com/communities/all/

That being said, when I worked with Salesforce doing some light coding, I always thought about the underlying database schema. What foreign key or pointer do we have in the table containing the threads that will connect the table that connects the emails. I believe the answer will be either the ParentId (the case) or the Message-ID (the original email) in the database. If you can somehow find and implement the link between the two, I bet your emails will thread properly.

If you have a Salesforce DBA, they might be a great reference to assist in understanding the link between the parent emails and the child (threaded) emails.