2

I am using AgentWork trigger in my logic and I cannot achieve code coverage goal.

Simple test method:

Id cId = [SELECT Id From Case Where Subject = 'Case Subject'].Id;
User u = [SELECT Id From User LIMIT 1];
ServiceChannel sc = [SELECT Id FROM ServiceChannel WHERE DeveloperName = 'Service_Channel_Test' LIMIT 1];

System.runAs(u)
{
    List<AgentWork> agentWorks = new List<AgentWork>();
    agentWorks.add(new AgentWork(WorkItemId = cId, UserId = u.Id, ServiceChannelId = sc.Id));

insert agentWorks;

}

returns

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]

Because of manipulation of UserServicePresence is not permitted then I cannot move forward. I suppose that, currently it is not supported by SFDC. Which is funny because test coverage is obligatory.

Do you have any experience with AgentWork unit tests?

Your Answer

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

Browse other questions tagged or ask your own question.