Delete Conversation Data with Flow or Apex
Call the Conversation Data API delete operations from Salesforce Flow or Apex instead of calling the REST API directly. When you use Flow or Apex, Salesforce handles authentication for you, so you don’t need to configure an External Client App or manage access tokens.
Two delete operations are available in both Flow and Apex:
| Operation | Description |
|---|---|
deleteConversationParticipantsByParticipantEntityId | Deletes a messaging end user and all of their messaging-related data. |
deleteConversationsById | Deletes one or more conversations and their associated data. |
For the full list of data that each operation deletes, see the deleteConversationParticipantData and deleteConversationsById schemas.
Both operations are asynchronous. When the call returns, the data isn’t deleted yet. The response has a 202 status and includes conversationApiLogs with a REQUESTED or ENQUEUED status for each requested ID. To confirm that a deletion is complete, query the ConversationApiLog records for their final status. See Query Conversation Data API Logs.
Before You Begin
Enable the Conversation Data API in your org. From Setup, in the Quick Find box, enter Conversation Service API, click Conversation Service API, and set the toggle to On. For more information, see Get Started with Conversation Data API. Until the API is enabled, the delete actions don’t appear in Flow Builder.
Delete Conversation Data with Flow
Add a delete operation to a flow as a Salesforce API Platform action.
- In Flow Builder, add an Action element.
- In the New Action window, search for and select one of these actions:
- Delete Conversation Participants By Participant Entity Id
- Delete Conversations By Id
- Enter a label for the action.
- Set the input values for the action you selected.
- For Delete Conversation Participants By Participant Entity Id:
- Participant Entity Id: A text collection variable that holds the Messaging End User IDs to delete. You can pass up to 50 IDs.
- Cascade Level:
FULL_CASCADE. This is the only supported value. It deletes all conversation data related to the participant.
- For Delete Conversations By Id:
- Conversation Entity Id: A text collection variable that holds the Conversation IDs to delete. You can pass up to 50 IDs.
- For Delete Conversation Participants By Participant Entity Id:
- Connect a fault path from the action so that your flow can handle any errors the delete operation returns. For information about the errors these operations can return, see Troubleshoot Errors.
Delete Conversation Data with Apex
Salesforce generates the ConversationApi.ConversationDelete class so that you can call the delete operations from Apex. Each operation has a corresponding request and response type.
To delete a messaging end user and their data, use deleteConversationParticipantsByParticipantEntityId.
1ConversationApi.ConversationDelete conv = new ConversationApi.ConversationDelete();
2
3ConversationApi.ConversationDelete.deleteConversationParticipantsByParticipantEntityId_Request request =
4 new ConversationApi.ConversationDelete.deleteConversationParticipantsByParticipantEntityId_Request();
5request.participantEntityId = new List<String>{ '0PAJS000001Y5Ud4AK', '0PAJS000001YD2S4AW', '0PAJS000001Y4744AC' };
6request.cascadeLevel = 'FULL_CASCADE';
7
8ConversationApi.ConversationDelete.deleteConversationParticipantsByParticipantEntityId_Response response =
9 conv.deleteConversationParticipantsByParticipantEntityId(request);To delete one or more conversations, use deleteConversationsById.
1ConversationApi.ConversationDelete conv = new ConversationApi.ConversationDelete();
2
3ConversationApi.ConversationDelete.deleteConversationsById_Request request =
4 new ConversationApi.ConversationDelete.deleteConversationsById_Request();
5request.conversationEntityId = new List<String>{ '0dw9R000000ZXYmQAO', '0dw9R000000ZXYrQAO', '0dw9R000000ZXYwQAO' };
6
7ConversationApi.ConversationDelete.deleteConversationsById_Response response =
8 conv.deleteConversationsById(request);The deleteConversationParticipantsByParticipantEntityId_Request type also supports the optional forceCloseSessions field. If forceCloseSessions is false or omitted, the deletion fails when a participant has an open messaging session. Set it to true to automatically close any open sessions before the deletion proceeds.
1request.forceCloseSessions = true;For details about the errors the delete operations can return, see Troubleshoot Errors and the deleteConversationParticipantData schema.