How to determine the remaining available Agent Capacity in Oni Channel via Apex Class. I have an agent who is assigned with the Presence Configuration where he can handle Maximum Capacity of 3, and he is currently assigned with the case of Size 2. In Omni Supervisor I can see

enter image description here

which means he can only take the item of size 1(which is the remaining available Capacity). I need to get the remaining available capacity through Apex. I tried the below and added the comments on each to show where it is going wrong

    public static List<Integer> getCapacity(List<ID> userId)
        List<Integer> availableCapacity = new List<Integer>();
        UserServicePresence[] usp= [SELECT Id,ConfiguredCapacity,createdbyId, UserId,IsCurrentState, ServicePresenceStatus.MasterLabel FROM UserServicePresence WHERE UserId =:userId and IsCurrentState = true AND ServicePresenceStatus.MasterLabel in ('All', 'Call','Case', 'Chat','Away','Break','Meeting','On a Call', 'Training')];  

        if(usp !=null && !usp.isEmpty())
            System.debug('Total Capacity ->' + usp[0].ConfiguredCapacity); /// Here I get usp.ConfiguredCapacity as 3 which is correct////
            Integer count = [SELECT Count() FROM AgentWork WHERE Status in ('Opened','Assigned') AND UserId = :userId];
            System.debug('Consumed Capacity ->'+ count); // This gives 1 as I am assigned with only one work item and not the capacity of the work item assigned to me 
            availableCapacity.add(usp[0].ConfiguredCapacity - count);  //This one gives 2 which is not correct and I am not using the corrent fields, I should get a 1 instead
        else {
        return availableCapacity;

Can anyone suggest how can I get the exact remaining capacity of the agent in the Omni Channel. Any help is greatly appreciated

1 Answer 1


According to the AgentWork documentation, you need to be using the CapacityWeight field to get the capacity that is actually assigned to the user rather than just counting the AgentWork records.

In this case, the query should be:

Integer assignedCapacity = [SELECT SUM(CapacityWeight) FROM AgentWork WHERE Status in ('Opened','Assigned') AND UserId = :userId];

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .