Updated – Integration of Salesforce with Toqan AI

🧠 What the system does

• Sends content from Salesforce (Case, EmailMessage, or MessagingSession) to Toqan for AI interpretation, and retrieves results such as: category, subcategory, and other extra fields defined in the prompt.
• Works with MessagingSession, EmailMessage, or Case objects.


🚀 How to use it (Quick overview)

1) Conversation Creation Flow (Start)

Trigger: Preferably After Save, when there is content to send and the Toqan context is not already populated.

Conditions:

  • MessagingSession: Body__c is filled.
  • EmailMessage / Case: Subject and Description or Body are filled.

In the Apex action (creation class), set:

  • recordId = Id of the Case / EmailMessage / MessagingSession
  • customLabelAPI = API name of the Custom Label containing the Toqan key (e.g., Toqan_Agent_Key)
  • isCase = true for Case; otherwise false
  • isEmail = true for EmailMessage; otherwise false
  • If both isCase and isEmail are false ⇒ treated as MessagingSession

What it does:
Sends the content to Toqan and saves the conversation context (as returned by Toqan’s create_conversation endpoint) — including conversationId, requestId, and agent — into the field Toqan_Conversation_JSON__c.


2) Response Retrieval Flow (Continuation)

Trigger: Preferably After Save, when Toqan_Conversation_JSON__c is populated or updated.

In the Apex action (get class), set:

  • recordId = Id of the Case / EmailMessage / MessagingSession
  • jsonInput = conversation data (conversationId, requestId, agent, etc.) from the create conversation API response

What it does:
Requests the result from Toqan and writes back:

  • CR1AI_T__cCategory [Main fields]
  • CR2AI_T__cSubcategory [Main fields]
  • Toqan_response_log__cFinal response or error log [Main + any secondary fields if present]

3) Parsing / Mapping Flow (Optional)

Trigger: After Save, when Toqan_response_log__c is populated or updated.

What it does:
Reads the response and maps values into desired custom fields (this can be extended without modifying Apex code).

Example:
If Toqan_response_log__c contains additional fields besides category and subcategory, you can parse the JSON to extract those values and populate custom fields on the object.


⚙️ Object-specific configurations (When call the apex class)

ObjectisCaseisEmailText Source
MessagingSessionfalsefalseBody__c
EmailMessagefalsetrueSubject + Email body
CasetruefalseSubject + Description

📊 Where to see the results

FieldDescription
Toqan_response_log__cFinal full response / errors
Toqan_Conversation_JSON__cConversation context (conversationId, requestId, agent, type of object)
CR1AI_T__cCategory
CR2AI_T__cSubcategory