Hello everyone. In this video we are
going to see how to automate Salesforce
omni channel agent present status using
Omni toolkit API.
The use case what I had was whenever
the agent's workload is changed
and uh if the agent workload is equal to
the configured capacity
then the agent's status should become
busy.
Let's say they close a work item because
of that the capacity is released. Now
they have additional capacity
so that they can work on additional work
items. In this case the omni channel
present status should automatically
change it to available.
In order to achieve this uh use case, in
order to automate the Salesforce agents
omni channel present status changes, I
am making use of lightning omni toolkit
API and omni channel workload changed
event.
I am making use of lightning aura
component because omni channel workload
changed event is not yet available in
Salesforce lightning web component
in the best practices and recommendation
I have documented it when you view this
uh video first check whether this
particular event
omni channel workload changed the event
is available in lightning web component
web component. If it is available try to
go with the latest Salesforce lightning
web component instead of lightning aura
component.
Okay. In my lightning aura component I
making use of lightning omni toolkit API
using aura handler. I'm listening to
lightning omni channel workload changed
event. Whenever the Salesforce agents
workload is changed, then it will invoke
on workload changed
in this JavaScript method.
I have hardcoded the busy status ID and
available status ID.
Try to try not to hardcode. I have added
that also in my
best practice and best practices and
recommendations.
So using
Omni uh so so using uh the toolkit. So
this Omni API is the toolkit.
So here I'm using component.find. Omni
toolkit. So from my from my component
I'm getting this uh omni toolkit using
which I'm making use of get uh service
present status ID. I'm trying to find
out what is the current present status
of the agent.
Then I am checking
uh then I'm making use of
so from the since it is an event from
the event I'm using get params method
and then from the from there from that
I'm getting the new workload previous
workload and configured capacity. So
this event
omni channel workload changed event will
uh have uh new workload previous
workload and configured capacity in
their params. So using the event or get
params I'm getting all those values and
then I'm checking whether their current
workload is greater than or equal to
configured capacity and also I'm
checking whether their current status ID
is not equal to busy status ID. If they
are already in busy status, I don't want
to make use of set agent present status
from my helper
uh JavaScript and set the status to busy
status ID. So in my helper I am making
use of the omni toolkit method set
service present status where I am
passing the status ID and then it will
be updating it. So if the agent's
workload is under their configured
capacity then
it will check whether the current status
ID is not equal to available status ID.
If they're already uh available and uh
if their status is available then I
don't want to uh again invoke this set
agent present status and update their
status. I wanted to update only when
they are not in available status. uh
let's say uh if uh my configured
capacity is two and uh the work item
capacity is one first time when I
receive work item
um I will be in available status. So
instead of again setting my status to
available using this uh uh JavaScript I
should avoid that instead of duplicating
my all duplicating my status again to
available. Same thing for setting it to
busy. If I get
um any
work item and if I'm already in busy, I
don't want to set my status again to
busy. I wanted to check it
uh if my status is not busy, then invoke
the helper method and pass the busy
status ID. Same thing is available for
available status. If if my status is not
available now, if I am busy or if I'm in
different status, then it will invoke
this method and then it will set my
status to available.
And uh in my service console app, I
added the lightning aura component. I
have set start automatically enabled so
that whenever they log in whenever the
page is loaded this lightning aura
component will be invoked and then uh
the event listener will start listening
to workload changed event.
So as of now in my presence
configuration the capacity is two. I am
making use of default presence
configuration. The capacity is two
and I have two cases that are in high
priority cases. Q the as per the uh
routing configuration the capacity for
each work item is one.
So now
let me go to inspect
console. Let me clear it. So now if I go
available for case
um two work items will be assigned to my
omni channel widget so that I will be
able to assign. One important thing to
note here is
the agent workload will be changed
when the work item is
assigned here in the omni channel
widget.
It won't get fired when they accept it.
Though the agent didn't accept the work
item, the workload changed event will be
fired. Their capacity would have been
already um um um deducted or applied
based on the work item routing
configuration capacity
and then it will invoke workload changed
event. So this is an important thing to
note. uh let me go available in case and
then we will see that in action. So here
if I go available uh as case two work
items will be um assigned one with uh
previous workload zero current workload
one configured capacity two. Second time
the second work item the previous will
be one current workload is two and the
configured capacity is uh two. So it is
equal. So it should set my status
directly to busy. So that's my
automation here. Uh if I um
decline a work item in my omni channel
um widget then it should release one
capacity because I didn't accept it. It
was just assigned to me but I didn't
accept it. So my status should be set
back to case. Let's see that in action.
So I'm setting my status to case.
It's it set my status to busy because
the agent cannot accept more work. So it
came to it came here. Agent cannot
accept more work and my current status
was available for case and it is not
busy. So it invoked set agent present
status from the helper and in the helper
with the help of set agent present
status method. Sorry. Set service
present status. Omni toolkit API method.
I was able to set the status to busy.
So new workload is one. Previous is
zero. Configured is two. Again the
workload changed because the second work
item was assigned. Previous work
workload was one. Configured is two. New
workload is two. So both are same. The
current status is this one. The new
status ID is this one. So it changed my
status from case to busy. Now if I
decline or if I accept and close the tab
because I'm making use of tab based
capacity model not status based. So if I
decline it should again trigger this
workload changed event and my cap and
then it should show the previous
workload should be two new workload
should be one and the configured
capacity is two. uh new workload and the
configured capacity are not same and
then it is less. So it should change my
status back to case. Let's see that. So
I'm declining it.
New workload is one. Previous workload
was two. So one was uh uh deducted and
the configured capacity is two. They are
not um equal and it is less. So the
current status ID is busy. Agent can
accept more work. So that's the reason
my status is changed to this new case
status ID. Sorry. Yeah, new present
status ID which is case. So it changed
and uh I was able to fully automate this
based on the workload changed event uh
information.
Please check the video description. In
the video description, I have shared my
blog post. From the blog post, you
should be able to get the lightning aura
component which we discussed in this
discussed in this video. And also, if
you are planning to make use of this
code and if you are planning to make use
of this approach, make sure to go over
the best practices and recommendations
for production ready code.
I hope it was helpful.
Thank you for watching.