📌 Overview
I developed a complete solution in Salesforce Service Console that automatically closes AgentWork records when a MessagingSession becomes Inactive or Ended, based on a country-specific timeout.
This functionality ensures that agent capacity is released automatically when customers leave a messaging session, eliminating the need for manual intervention from the agent.
🧩 Technologies Used
- Aura Components (Lightning UI for Service Console)
- Apex Controller (backend logic with
MessagingSessionintegration) - Omni-Channel Toolkit API (
lightning:omniToolkitAPI) - Custom Labels for country-based timeout configuration
- LocalStorage for timer persistence across page refreshes
✅ Key Features
- Automatic country detection based on
MessagingChannel.DeveloperName - Flexible timeout configuration via custom label
(e.g.,RO:30;BG:30;HU:40) - Automatic AgentWork closure using Omni Toolkit’s
closeAgentWorkmethod - Persistent countdown timer that resumes after Lightning page refresh
- Dynamic UI feedback for session state:
- 🔄 Monitoring active…
- ⏳ Session will close in X seconds…
- ✅ Session closed successfully
- ℹ️ No active AgentWork to close.
🧪 Testing & Quality
- Dedicated Apex test class
- 100% code coverage for backend business logic
- Isolated label parsing logic for enhanced testability
- Reactive and synchronized UI tied to real-time session status
🧠 Outcome
This solution significantly reduces the number of abandoned chat sessions that block agent slots, improves support team efficiency, and automates repetitive steps for agents.


