4

I have a requirement to get the list of online agents with available capacity. I could get the online agent list by querying UserServicePresence, But I can't figure out how to get the current available capacity (not the maximum capacity).

I tried querying AgentWork, but that doesn't feel like the right way to do it.

Incidentally, the code will need to execute in a batch context, so I don't think there is a way to make use of the Console Toolkit or lightning:omniChannelWorkloadChanged

4
  • 1
    are you not able to query for "ConfiguredCapacity" on UserServicePresence for those with isCurrentState = true and add it up? Or am I misunderstanding what you're looking for? – Kris Goncalves Dec 26 '19 at 18:45
  • I was able to query "ConfiguredCapacity" on UserServicePresence, but that only gives me total capacity. If the agent's current workload is (0/3). I am getting '3' not the '0' which is the current capacity. – Nithesh N Dec 26 '19 at 19:02
  • 2
    Thanks for clarifying. I do think a combo of UserServicePresence and AgentWork is the way to do it. One to get who is online and the other to get the # of "opened" work (meaning current workload for each). I haven't personally done this so you may be aware of why that doesn't seem to meet your need. – Kris Goncalves Dec 26 '19 at 19:56
  • This looks interesting, do post if you find a solution. Good luck. @NitheshN – Atlas Can Dec 27 '19 at 6:34
4

As Kris suggested, I have used similar to make a custom omni supervisor component, you can use status of AgentWork and UserServicePresence to find out current capacity of the Agent.

UserServicePresence usp= [SELECT Id,ConfiguredCapacity FROM UserServicePresence WHERE IsCurrentState = true AND ServicePresenceStatus.MasterLabel ='Available' AND UserId=:UserInfo.getUserId()];

System.debug('Total Capacity ->' + usp.ConfiguredCapacity);

Integer count = [SELECT Count()
FROM AgentWork
WHERE Status = 'Opened'
AND CreatedById = :UserInfo.getUserId()]; 
System.debug('Consumed Capacity ->'+ count);

there would be other considerations you need to make based on how you are using presence statues. eg when agent was available the workitem was allocated to them, but when they go busy, on break, it would still be able to allocate to them.

1
  • 1
    Thanks Pranay! I think my query is pretty similar to this but I am including Assigned Status too. – Nithesh N Dec 27 '19 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.