function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Erik BurtonErik Burton 

How to log out an omni channel presence agent through apex?

I have a scheduled apex class that automatically adds and removes users from particular queues at different times during the day.  However, to have these queue membership changes reflected omni-channel, the agents need to set themselves to offline, then available (or away) again.

I would like to automate this for them, by logging an agent out after I've updated their queue membership.  However, I cannot find a way to log an agent out of omni-channel through Apex.  I cannot delete a UserServicePresence object, nor can I update the "IsCurrentStatus" field of that object.

There is a handy api call available in the console integration toolkit (https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_logout.htm) but that would require VisualForce instead, and a completely different implementation approach.

Has anyone else found a way to set an agent's presence status through Apex?  Thanks!
PawanKumarPawanKumar
Hi Erik,
Even i tried the same last week to cover Agent Work trigger for my code coverage. But came to know that we can not change status using Apex as UserServicePresence object does not support DML operations. Please refer below documents.

https://developer.salesforce.com/docs/atlas.en-us.omni_channel_dev.meta/omni_channel_dev/sforce_api_objects_userservicepresence.htm

Regards,
Pawan Kumar