Auto Create Case for Complaint in Contact Description
Business Requirement:
Whenever a Contact is created or updated, and the Description field contains any complaint-related keyword like “Complaint”, “Problem”, or “Issue”, the system should automatically create a High Priority Case.
Why is this useful?
- Automatically tracks complaints raised by customers
- Reduces manual work for service agents
- Ensures no complaint is missed or delayed
Business Value:
- ✔ Improves customer satisfaction
- ✔ Ensures faster response to issues
- ✔ Better complaint management workflow
Objects & Fields Involved:
- Contact (Standard Object)
- Description (Text Field)
- Case (Standard Object)
- Subject, Priority, Status, ContactId (Case Fields)
Apex Trigger Code:
trigger CreateCaseOnContactComplaint on Contact (after insert, after update) {
List<Case> caseList = new List<Case>();
for (Contact con : Trigger.new) {
String de = con.Description != null ? con.Description.toLowerCase() : '';
if (de.contains('complaint') || de.contains('problem') || de.contains('issue')) {
Case cs = new Case(
Subject = 'Complaint from ' + con.FirstName,
Priority = 'High',
Status = 'New',
ContactId = con.Id
);
caseList.add(cs);
}
}
if (!caseList.isEmpty()) {
insert caseList;
}
}
Example Scenario:
Contact Description: “Customer raised a complaint about payment issue.”
Result: A High Priority Case is automatically created and linked to the Contact.
Real-Time Use Cases:
- B2C Companies receiving complaints via forms
- Salesforce Service Cloud implementations
- Auto-escalation of issues in support teams