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
Kshitij LawateKshitij Lawate 

Test class for Trigger on AgentWork

We have a trigger on object AgentWork. We are trying create a test class for the same. While inserting test data, we get below error. 


System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, The agent's status is not associated with the channel for this work.: [ServiceChannelId]

Any inputs? Thanks. 
Kshitij LawateKshitij Lawate
To add more, we have this AgentWork trigger for assigning a custom object work item to user. 
Dilip_VDilip_V
Kshitij,

FIELD_INTEGRITY_EXCEPTION comes when you are assigning wrong Id to a field.

Ex:Populating contact Id for accountID.

Share the code.

Let us know if you have any problems.
Mark it as best answer if it works.

Thanks.
Kshitij LawateKshitij Lawate
The code is as below. 
 
List<AgentWork> awList = new List<AgentWork>();
        
        for(Integer temp = 0; temp < countAW; temp ++)
        {
        	AgentWork aw = new AgentWork();
        	aw.UserId = userId; 
        	aw.ServiceChannelId = serviceChannelId;
        	aw.WorkItemId = workItemId; 
        	awList.add(aw);
        }
        
        return awList;

The issue happens because the Service Channel mentioned in code is associated with a particular Omni-channel status value. 

When running the test class, my Omni-channel status was Offline, while the Service Channel is associated with 'online' status. 

In order to resolve the issue, I made myself Online on Omni-channel and then ran the class. It was executed successfully. 

Above could be one of the solution, but if anyone else has any solution, please feel free to comment. 
Anamika JakhmolaAnamika Jakhmola

Hi All,

Similar to the above but for different requirement i have tried by making me as "available" on omni-channel , it worked for my Developer org however while validating it to deploy through CICD on other org eventhough i did the same step. I am still getting the error:
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, The agent's status is not associated with the channel for this work.: [ServiceChannelId]

Please suggest. What can be done to resolve this?

Regards,

Anamika

Justin Milburn 5Justin Milburn 5
I hate to advocate this as an option, but if the goal is only to allow for test coverage greater than 0%, here's a possibility: we use a trigger framework that allows a single trigger to call multiple classes. We ended up using a delete trigger to force the Trigger to fire, where the extended class did literally nothing. This forced the trigger class to register 100% coverage and allowed for deployment. 

I'm sorry