
How to Mass Delete Salesforce Messaging Users and Related Data via the Conversation Data API?
In today’s regulatory landscape, managing data privacy is not just a best practice—it’s a requirement. With regulations like GDPR and CCPA, Salesforce customers often need mechanisms to fulfill “Right to be Forgotten” requests efficiently.
For organizations using Salesforce Digital Engagement (Messaging), simply deleting a contact record doesn’t always scrub the associated conversational history held in Messaging User records, transcripts, and sessions.
Today, we’ll explore how to use the Salesforce Conversation Data API to programmatically and comprehensively delete Messaging Users and their associated conversational data.
What is the Conversation Data API?
The Conversation Data API is a powerful set of REST resources that allows developers to manage conversational data at scale. While often used for retrieving data for analysis, it is also the primary tool designed for compliant data deletion across engagement channels like SMS, WhatsApp, and Facebook Messenger integrated with Salesforce.
By using this API, you ensure a “clean sweep” of messaging data, rather than relying on manual, multi-step deletions in the UI.
Prerequisites
Before you can make API calls to delete data, you need to ensure your Salesforce environment is configured correctly.
- Enable Conversation Service APIs: Navigate to Salesforce Setup and ensure that the Conversation Service APIs are enabled for your org.
- Configure an External Client App (Headless): You need secured access to the API. Set up an External Client App to handle authentication. Please refer to the official Salesforce documentation for the exact steps: Get Started with the Conversation Data API.
Step-by-Step Guide to Deletion
Once your prerequisites are met, the process involves two main steps: authenticating and issuing the delete command.
Step 1: Get an Access Token
To interact with the Conversation Data API, you first need a valid OAuth access token. You obtain this by making a POST request to your Salesforce domain’s token endpoint.
Request Type: POST
Endpoint: https://{Your-Salesforce-Domain}.my.salesforce.com/services/oauth2/token
(Ensure you include the necessary client_id, client_secret, grant_type, and other required parameters in the body of your request based on your External Client App configuration.)
Step 2: Send the DELETE Request
Once you have your access token, you can issue the deletion request. This request targets specific participantEntityId values. In the context of Salesforce Messaging, these IDs correspond to the Messaging User record IDs (typically starting with 0PA).
A crucial aspect of this API call is the cascadeLevel parameter. Setting this to FULL_CASCADE ensures that when the Messaging User is deleted, all related data—such as conversation transcripts and messaging sessions associated with that user—are also deleted.
Request Type: DELETE
Endpoint Example:
https://api.salesforce.com/platform/engagement/v1.0/conversation-participants?participantEntityId=0PAHo000000MWydOAG, 0PAHo0000017CRrOAM, 0PAHo0000018xB3OAI&cascadeLevel=FULL_CASCADE
Understanding the Parameters in the example:
participantEntityId: A comma-separated list of the Messaging User Ids you wish to delete (e.g.,0PAHo000000MWydOAG, 0PAHo0000017CRrOAM...).cascadeLevel=FULL_CASCADE: This instructs the system to perform a deep delete of related interaction data.
Important Note: Asynchronous Processing
It is vital to understand that this API call does not perform an immediate, synchronous deletion.
When you issue the successful DELETE request, the Salesforce platform enqueues deletion jobs. The actual removal of data will happen asynchronously in the background. You should build your integration to expect a “202 Accepted” response, acknowledging the request has been queued, rather than an immediate confirmation of deletion.
Resources:
Sample Apex Code to get 3 Messaging End User Ids:
Set < Id > setMEUIds = new Set < Id >();
for ( MessagingEndUser objMEU: [
SELECT Id
FROM MessagingEndUser
LIMIT 3
]
) {
setMEUIds.add( objMEU.Id );
}
System.debug(
setMEUIds
);