Automating Salesforce Case Fields (Priority, Reason, and Type) Using AI

7/17/2025

Introduction

This Accelerator System API enables automated support ticket classification in Salesforce Service Cloud using a Large Language Model (LLM). It ingests unclassified cases, uses LLM inference to predict metadata—Type, Reason, and Priority—and updates the Salesforce Case record accordingly and sends email reports. It also handles retry logic, fallback alerts, and logging to ensure reliability and traceability. 

Although originally implemented with open-source models hosted on Groq Cloud, the accelerator is fully compatible with any LLM provider. You can seamlessly switch between platforms like Groq, OpenAI, Anthropic, Google Gemini, or self-hosted/open-source models—simply by updating the API endpoint, model name, credentials, and http request payload based on the platform. Please refer to the change platform/ switch LLM provider section for details.
 

Objective

Automatically populate the following fields on a Case record based on the Description and the Subject using AI.

S.NoField Name
1Priority
2Type
3Reason

 

Getting Started

You can find the demo implementation on Github

Connectors Used

S. NoConnector
1Salesforce
2HTTP Request
3Object Store
4SMTP

 

Setting the mule.env System Property

To enable environment-based property loading (e.g. dev-config.yaml, qa-config.yaml, prod-config.yaml), configure mule.env in VM arguments in the anypoint studio

Required property overrides

The following properties must be provided to reflect the target environment.

AI Classification Configuration

PropertyDescriptionExample / Default
ai.apikeyAPI key for the LLM providergsk_****
ai.chatEndPointAPI endpoint for chat-based completionhttps://api.groq.com/openai/v1/chat/completions
ai.modelModel name or versionqwen/qwen3-32b
ai.temperatureResponse randomness (0 = deterministic)0.6
ai.top_pNucleus sampling value0.95
ai.max_completion_tokensToken limit per response4096
ai.retriesNumber of retry attempts on failure5
ai.milliSecondsBetweenRetriesTime between retries60000 (ms)
ai.recordsBatchSizeNumber of tickets to classify in one request10


 

Salesforce Configuration

This template uses salesforce JWT authentication, if you prefer to use other methods of authentication methods update the yaml files under src/main/resources/config  and the salesforce connector configuration in global-config.xml 

PropertyDescriptionExample
sf.consumer_keySalesforce Connected App consumer key3MVG9dAEux2v1sLvyR1F...
sf.store_passwordEncrypted passwordpassword
sf.principal_userPrincipal integration userusername@agentforce.com

 


 

 

Salesforce Case Metadata Mapping

FieldPossible Values
PriorityLow, Medium, High
TypeElectrical, Electronic, Mechanical, Structural, Others etc.
ReasonInstallation, Equipment Complexity, Performance, Breakdown, Feedback etc.


 These should match the Salesforce Case object picklist values.

Email Notification Configuration

PropertyDescriptionExample
mail.hostSMTP server hostnamesmtp.gmail.com
mail.portSMTP port587
mail.usernameSender emailexample@gmail.com
mail.passwordApp passwordlkozlqyweonkrohd
alertContact.emailRecipient for email alertsadmin@example.com


 

 

 

Example Config Reference 

service:
  name: "ai-sfdc-case-ticket-classifier-accelerator-sys-api"
  env: "dev"

ai:
  apikey: "apikey"
  chatEndPoint: "https://api.groq.com/openai/v1/chat/completions"
  model: "qwen/qwen3-32b"
  temperature: "0.6"
  top_p: "0.95"
  max_completion_tokens: "4096"
  retires: "5"
  milliSecondsBetweenRetries: "60000"
  recordsBatchSize: "10"


mail:
  host: "smtp.gmail.com"
  port: "587"
  username: "username@gmail.com"
  password: "lkozlqyweonkrohd"
  

sf:
  consumer_key: "salesforce app consumer key"
  store_password: "password"
  principal_user: "username@agentforce.com"
  
sf_case:
  priorities:
    - "Low"
    - "High"
    - "Medium"
  types:
    - "Electrical"
    - "Electronic"
    - "Mechanical"
    - "Structural"
    - "Others"
  caseReasons:
    - "Installation"
    - "Equipment Complexity"
    - "Performance"
    - "Breakdown"
    - "Equipment Design"
    - "Feedback"
    - "Others"


alertContact:
  email: "example@companyname.com"
  
  
  

Solution Approach 

Scheduler Configuration (MuleSoft)

The process is triggered once per day using MuleSoft’s Scheduler component.

0 0 0 ? * *  

Query Salesforce for New/Unclassified Cases

Using the Salesforce Connector, MuleSoft runs a SOQL query to fetch recent cases for classification:

SELECT Id, CreatedDate, Reason, Type, Subject, Description, Priority 
FROM Case 
WHERE Reason = NULL 
LIMIT 10

This fetches only unclassified records. You can refine this filter based on your business logic (e.g., Priority = NULL or date-based cutoffs). 


Transform Data with DataWeave

MuleSoft's DataWeave script transforms the case records into a format usable by the AI prompt:

%dw 2.0
output json
---
payload map (case) -> {
 id: case.Id,
 subject: case.Subject,
 description: case.Description
}

AI Prompt: 

%dw 2.0
output json
import * from dw::core::Strings
import p from Mule



var caseInput = payload map {
    subject: $.Subject,
    description: $.Description, 
    id: $.Id
}

var aiPrompt = `
Your Role:
You are an advanced AI assistant acting as a Salesforce Support Bot.

Your Primary Goal:
Analyze an incoming support tickets (Salesforce Case objects provided in JSON format) and determine their correct classification and priority based on a set of defined rules and categories.

Context & Rules:

Classification: You must choose the single most appropriate classification from the provided list. Your decision should be based on the ticket's Subject and Description.

Priority: You must determine the ticket's priority based on the urgency and impact described in the Subject and Description. Your assessment overrides any priority that may already be present in the ticket data. Use the following logic:

High: The issue completely blocks a user or a critical business process. Examples include: inability to log in, system-wide outages, data loss, security vulnerabilities, or major feature malfunction preventing work.

Medium: The issue impairs a feature's functionality but has a workaround, or the impact is limited and not a complete blocker. Examples include: data discrepancies that don't halt work, performance degradation, or issues with a non-critical feature.

Low: The issue is a general inquiry, a cosmetic bug, a feature request, or has minimal impact on the user's workflow.

Reference Data:

Available Types: $(p('sf_case.types'))

Available Reasons: $(p('sf_case.caseReasons'))


Available Priorities:
[
"High",
"Medium",
"Low"
]

Your Task:
For the tickets provided below, analyze its content according to the rules and generate a JSON object containing the ticket's ID, your determined classification, and your determined priority.

Output Requirements:

Your response must be only the final JSON object.

Do not include any text, explanations, or markdown formatting (like \`\`\`json) before or after the JSON.

The output JSON must follow this exact format: {
    "id": {
        "type": "...", "reason": "..." "priority": "..."
    },
      "id": {
        "type": "...", "reason": "..." "priority": "..."
    },
      "id": {
        "type": "...", "reason": "..." "priority": "..."
    }

}

Ticket to Analyze:
$(write(caseInput))

`
---
aiPrompt


This creates a structured prompt with business rules, classification logic, and formatting constraints for the AI.
 

Example Output Prompt:

{
  "5005h00001ABCDE": {
    "type": "Problem",
    "reason": "Payment",
    "priority": "High"
  }
}

Parse AI Response & Update Salesforce

 

Once the JSON is returned from the AI:

MuleSoft parses the object

Iterates over the case ID keys

Maps the values to Salesforce fields

Uses the Salesforce Update Connector to patch each Case record with the AI-predicted: Type, Reason and Priority. 


Conclusion


In this project, we demonstrated how to use MuleSoft, Salesforce, and AI to automate the classification and prioritization of Salesforce Case records. By integrating a scheduled MuleSoft flow with an AI prompt engine and Salesforce data, we created an intelligent, hands-off workflow that reduces manual effort, ensures consistency, and accelerates case triage.