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
hemanth.bak1.3960095498200388E12hemanth.bak1.3960095498200388E12 

OMNI Channel - Trigger & control the owner change

Background of the issue:
We have just started exploring the option of using OMNI Channel for our service cloud CSR user. I have turned on omni channel settings in my Dev org. I have set up the routing and service channel configurations for omni channel for a custom object. In our org, for contacts we have custom sharing settings (On contact object, we have a restricted flag, if a contact is restricted, then only certain roles can see that contact). On the custom object record, we have a lookup to contact, with OMNI Channel when we assign the custom object record to a Queue, if that custom object record's contact is restricted then that Queue user is not supposed to accept that custom object record.

Question:
When the user clicks "Accept" in OMNI Channel, we wrote a trigger on the custom object record, to control the change of owner, however, OMNI Channel Agent's accept does not fire the trigger on the custom object for which the owner is getting changed.

I would like to undestand, why the trigger on the custom object record does not fire, when the owner is changed from Queue to a User, when the User clicks "Accept" through OMNI Channel.

Is there any way to write trigger on Agentwork object? Please advice..
 
Here-n-nowHere-n-now
The trigger on the custom object does NOT fire when Omni Channel assigns it.  That is by design.
https://help.salesforce.com/apex/HTViewSolution?id=000228601&language=en_US
Nicolás KacowiczNicolás Kacowicz
There's a WorkAround.
Whenever the Omnichannel assign a record to an Agent, an AgentWork record gets created.

You can create a Process Builder and then call an Apex method if you have custom logic that you want to execute.

https://help.salesforce.com/articleView?id=omnichannel_agent_work_fields.htm&type=0 (https://help.salesforce.com/articleView?id=omnichannel_agent_work_fields.htm&type=0)